简体   繁体   English

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

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

I am new to .net core and attempting a web app with a login page that uses the provided authentication features in asp .net-core. 我是.net核心的新手,并尝试使用登录页面的Web应用程序,该登录页面使用asp .net-core中提供的身份验证功能。

When I created the web app and built it up, I used IISExpress to run it and the authentication features worked correctly and allowed me to login and use various operations on the web app. 当我创建Web应用程序并构建它时,我使用IISExpress运行它并且身份验证功能正常工作,并允许我登录并在Web应用程序上使用各种操作。

I am now attempting to change from IIExpress to Kestrel and running into some difficulty with authenticating users on logon. 我现在正试图从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

So, when using Kestrel, the user is "logged in" correctly as the user/password entered is correct. 因此,当使用Kestrel时,用户正确地“登录”,因为输入的用户/密码是正确的。 And therefore it is meant to redirect to Index, or /. 因此,它意味着重定向到索引,或/。

  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 ().

However, the above error messages arise in the console, and the page eventually redirects back to the login page without the user logged in. 但是,上述错误消息出现在控制台中,并且页面最终会重定向回登录页面,而无需用户登录。

In my startup Configure method, I have added the following line that a lot of answers seem to show the fix as but it does not make a difference (as it was already there) 在我的启动配置方法中,我添加了以下行,很多答案似乎都显示了修复,但它没有区别(因为它已经存在)

            app.UseAuthentication();

If it's useful, in my ConfigureServices Method I am setup as follows: (with a little bit more to specify password settings) 如果它有用,在我的ConfigureServices方法中我设置如下:(稍微多一点来指定密码设置)

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

I am curious to what the problem could be since it works correctly on IIExpress but not on Kestrel. 我很好奇问题可能是什么,因为它在IIExpress上正常工作但在Kestrel上没有。 If you need me to provide any more code please let me know. 如果您需要我提供更多代码,请告诉我。 Any help in the matter would be greatly appreciated. 任何有关此事的帮助将不胜感激。 Thanks. 谢谢。

EDIT - Cookie configuration in ConfigureServices : 编辑 - 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;
            });*/

I have essentially followed this tutorial for creating this, and I don't believe there are many changes from this: Introduction to Identity on ASP.NET Core 我基本上按照本教程来创建它,我不相信有很多变化: ASP.NET Core上的Identity简介

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

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

相关问题 在 Windows 身份验证的 ASP.Net 5 中使用 IIS Express/Kestrel 时,User.IsInRole 始终为 false - User.IsInRole is always false when using IIS Express / Kestrel in ASP.Net 5 with Windows Authentication 调试 IIS Express 认证问题 - Debugging IIS Express authentication issue MVC 身份验证在 IIS 中不起作用(在 IIS Express 中起作用) - MVC Authentication not working in IIS (works in IIS Express) MVC 5 身份验证在 IIS Express 中工作但不在 IIS 中 - MVC 5 Authentication working in IIS Express but not in IIS 使用 SOAP 服务和 IIS 的 Windows 身份验证失败 - Windows authentication with SOAP service and IIS failing 设置DBContext时出现ASP.NET Core 2.2错误(在Kestrel中起作用,不在IIS Express中起作用) - ASP.NET Core 2.2 error when setting up DBContext (works in Kestrel, not in IIS Express) ASP.Net Core 2-Powershell远程处理仅在IIS Express中有效(Kestrel无法正常工作) - ASP.Net core 2 - powershell remoting works only in IIS Express (Kestrel not working) IIS Express中使用Active Directory进行MVC身份验证/授权 - MVC Authentication/Authorization with Active Directory in IIS Express 如何使IIS Express与表单身份验证一起使用 - How to get IIS Express to work with Forms Authentication 直接连接到IIS后的Kestrel - Connect directly to Kestrel behind IIS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM