小编Raw*_*wcy的帖子

身份验证在 Kestrel 上失败,但在 IIS Express 上没有

我是 .net core 的新手,正在尝试一个带有登录页面的 web 应用程序,该页面使用 asp .net-core 中提供的身份验证功能。

当我创建并构建 Web 应用程序时,我使用 IISExpress 来运行它,并且身份验证功能正常工作,并允许我登录并使用 Web 应用程序上的各种操作。

我现在正在尝试从 IIExpress 更改为 Kestrel,但在登录时对用户进行身份验证时遇到了一些困难。

info: RestartTool.Controllers.AccountController[0]
  User logged in.
info: Microsoft.AspNetCore.Mvc.RedirectToActionResult[1]
  Executing RedirectResult, redirecting to /.
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
  Executed action RestartTool.Controllers.AccountController.Login (RestartTool) in 3330.8233ms
Run Code Online (Sandbox Code Playgroud)

因此,在使用 Kestrel 时,用户将正确“登录”,因为输入的用户名/密码是正确的。因此它意味着重定向到索引或 /。

  Request starting HTTP/1.1 GET http://localhost:59211/
info: Microsoft.AspNetCore.Authorization.DefaultAuthorizationService[2]
  Authorization failed for user: (null).
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[3]
  Authorization failed for the request at filter 'Microsoft.AspNetCore.Mvc.Authorization.AuthorizeFilter'.
info: Microsoft.AspNetCore.Mvc.ChallengeResult[1]
  Executing ChallengeResult with authentication schemes ().
Run Code Online (Sandbox Code Playgroud)

但是,上面的错误信息出现在控制台中,页面最终在用户未登录的情况下重定向回登录页面。

在我的启动配置方法中,我添加了以下行,很多答案似乎都显示了修复程序,但它没有区别(因为它已经存在)

            app.UseAuthentication();
Run Code Online (Sandbox Code Playgroud)

如果有用,在我的 ConfigureServices 方法中,我的设置如下:(多一点来指定密码设置) …

c# asp.net-core

5
推荐指数
1
解决办法
403
查看次数

标签 统计

asp.net-core ×1

c# ×1