繁体   English   中英

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

[英]Authentication failing on Kestrel but not on IIS Express

我是.net核心的新手,并尝试使用登录页面的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

因此,当使用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 ().

但是,上述错误消息出现在控制台中,并且页面最终会重定向回登录页面,而无需用户登录。

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

            app.UseAuthentication();

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

  services.AddIdentity<ApplicationUser, IdentityRole>()
                .AddEntityFrameworkStores<ApplicationDbContext>()
                .AddDefaultTokenProviders();
services.AddMvc();

我很好奇问题可能是什么,因为它在IIExpress上正常工作但在Kestrel上没有。 如果您需要我提供更多代码,请告诉我。 任何有关此事的帮助将不胜感激。 谢谢。

编辑 - ConfigureServices Cookie ConfigureServices

/* services.ConfigureApplicationCookie(options =>
            {
                // Cookie settings
                options.Cookie.HttpOnly = true;
                options.Cookie.Expiration = TimeSpan.FromDays(150);
                options.LoginPath = "/Account/Login"; // If the LoginPath is not set here, ASP.NET Core will default to /Account/Login
                options.LogoutPath = "/Account/Logout"; // If the LogoutPath is not set here, ASP.NET Core will default to /Account/Logout
                options.AccessDeniedPath = "/Account/AccessDenied"; // If the AccessDeniedPath is not set here, ASP.NET Core will default to /Account/AccessDenied
                options.SlidingExpiration = true;
            });*/

我基本上按照本教程来创建它,我不相信有很多变化: ASP.NET Core上的Identity简介

我已经通过登出II Express页面解决了这个问题,然后它就可以登录并验证在Kestrel上成功运行了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM