Authentication failed on Kestrel, but not on IIS Express

I am new to the .net kernel and am trying to create a web application with a login page that uses the provided authentication features in asp.net-core.

When I created the web application and created it, I used IISExpress to launch it, and the authentication functions worked correctly and allowed me to log in and use various operations in the web application.

Now I am trying to switch from IIExpress to Kestrel and run into some difficulties with user authentication at login.

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 "logged in" correctly, as the user entered / password is entered correctly. And therefore, it is intended 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 ().

, .

Configure Configure , , , , ( )

            app.UseAuthentication();

, ConfigureServices : ( , )

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

, , IIExpress, Kestrel. , , , . . .

EDIT - 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;
            });*/

, , : Identity ASP.NET Core

+4
1

, II Express, Kestrel..

+1

Source: https://habr.com/ru/post/1693747/


All Articles