我是.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配置:
/* 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;
});*/
我基本上已经按照本教程创建了这个,但我不相信这有很多变化:Introduction to Identity on ASP.NET Core
答案 0 :(得分:2)
我已经通过登出II Express页面修复了问题,然后它就能登录并验证在Kestrel上成功运行..