簡體   English   中英

當應用程序以“開始而不調試”運行時,用戶未被識別為已登錄,當以“開始調試”運行時,用戶身份驗證工作正常

[英]User not recognized as logged in when application is run as Start Without Debugging, user authentication works perfectly when run as Start Debugging

我在 Visual Studio 2019 中構建了一個小型 ASP.NET Web 應用程序,從 VB 的 ASP.NET MVC Web 應用程序項目模板開始,它使用默認的個人用戶帳戶進行身份驗證。 我的開發接近尾聲,在此過程中的某個地方,當我在沒有通過 CTRL-F5 附加調試器的情況下運行應用程序時,我失去了登錄應用程序的能力:不調試啟動。 運行帶有通過 F5 附加調試器的應用程序:啟動調試和任何其他附加調試器的運行方法都允許應用程序按預期運行。

啟動時,Web 應用程序要求用戶登錄。登錄成功后,預期行為是重定向到主頁,但目前登錄成功只會再次顯示登錄頁面,我相信應用程序無法識別用戶已通過身份驗證。

我開始使用舊的清理、重新編譯和重建進行調試,但在那里沒有任何運氣。 在登錄方法的成功語句中添加了 throw 語句並驗證登錄嘗試是否成功。 帶有此 throw 語句的登錄方法(位於AccountController.vb )如下所示。 登錄嘗試確實會觸發SignIn.Success案例。

' POST: /Account/Login
<HttpPost>
<AllowAnonymous>
<ValidateAntiForgeryToken>
Public Async Function Login(model As LoginViewModel, returnUrl As String) As Task(Of ActionResult)
    If Not ModelState.IsValid Then
        Return View(model)
    End If

    ' This doesn't count login failures towards account lockout
    ' To enable password failures to trigger account lockout, change to shouldLockout := True
    Dim result = Await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout := False)
    Select Case result
        Case SignInStatus.Success
            Throw New System.Exception("Sign In Succeeded") 'Throws both with and without the debugger attached
            Return RedirectToLocal(returnUrl)
        Case SignInStatus.LockedOut
            Return View("Lockout")
        Case SignInStatus.RequiresVerification
            Return RedirectToAction("SendCode", New With {
                returnUrl,
                model.RememberMe
            })
        Case Else
            ModelState.AddModelError("", "Invalid login attempt.")
            Return View(model)
    End Select
End Function

奇怪的是,即使我刪除了項目中僅有的兩個<Authorize>屬性,無法登錄仍然存在,我認為這會一起消除登錄屏幕。 (它們附加到AccountControllerManagerController類,它們的位置與我過去使用相同項目模板完成的其他項目相匹配)

我能找到的唯一相關的互聯網資源之一就是這個問題 我正在構建和部署到 targetFramework 4.7.2,我的 web.config 文件是由項目模板生成的,數據庫連接字符串除外,但我已經包含了它,以防有人發現錯誤。

<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=my secret token" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=very secret connection string"
         providerName="System.Data.SqlClient" />
  </connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <authentication mode="None" />
    <compilation debug="true" targetFramework="4.7.2" />
    <httpRuntime targetFramework="4.7.2" />
    <roleManager enabled="true" defaultProvider="MySqlRoleProvider">
      <providers>
        <add name="MySqlRoleProvider"
        type="System.Web.Security.SqlRoleProvider"
        applicationName="RFIDDataEntry"
        connectionStringName="DefaultConnection"/>
      </providers>
    </roleManager>
  </system.web>
  <system.webServer>
    <modules>
      <remove name="FormsAuthentication" />
    </modules>
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      ....
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
  </system.codedom>
</configuration>

TLDR:當我的 VB.NET Web 應用程序在沒有附加調試器的情況下運行時,即使登錄嘗試成功,我的 VB.NET Web 應用程序也無法識別用戶已登錄。

我能夠通過刪除.vs文件夾來解決這個問題。

最近幾天我也遇到了同樣的問題。 我的瀏覽器是 Edge Developer。 刪除 .vs 文件夾后,問題仍然存在。 然后我從瀏覽器和 Voila 中刪除所有緩存,問題解決了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM