ASP.NET Core Identity & Cookies

后端 未结 2 649
臣服心动
臣服心动 2021-01-07 04:14

I have an ASP.NET Core site using AspNetCore.Identity.EntityFrameworkCore 1.1.1 and cookies to authorize/authenticate my users. No matter what I choose as my setting in the

2条回答
  •  猫巷女王i
    2021-01-07 04:46

    You do not need a separate CookieAuthentication middleware when you are using ASPNET identity. UseIdentity() will do that for you and generate a cookie. You can set the "cookie options" in the AddIdentity block of the application like so:

         services.AddIdentity(config =>
                {
                    //  Require a confirmed email in order to log in
                    config.SignIn.RequireConfirmedEmail = true;
    
                   // Your Cookie settings
                  config.Cookies.ApplicationCookie.ExpireTimeSpan = TimeSpan.FromDays(1);
                  config.Cookies.ApplicationCookie.LoginPath = "/Account/LogIn";
                  config.Cookies.ApplicationCookie.LogoutPath = "/Account/LogOut";
                }).AddEntityFrameworkStores

    Also, take a look at https://stackoverflow.com/a/34981457/1137785, it gives a background of this sort of a scenario with a very good explanation.

提交回复
热议问题