首页 > 解决方案 > ASP.NET Core 身份验证 cookie 不会过期

问题描述

在 IIS 中部署应用程序时,cookie 不会过期。使用 VS + IIS Express 进行测试时,一切正常。请参阅上面的设置。

在启动中:

app.UseCookieAuthentication(new CookieAuthenticationOptions
 {
   AuthenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme,
   AutomaticAuthenticate = true,
   ExpireTimeSpan = TimeSpan.FromMinutes(3),
   CookieSecure = env.IsDevelopment() ? CookieSecurePolicy.SameAsRequest : 
   CookieSecurePolicy.Always
 });

在控制器中:

var principal = new ClaimsPrincipal(new ClaimsIdentity(GetUserClaims(claims, response.ContentObject.Jwt, username), CookieName));
await HttpContext.Authentication.SignInAsync(CookieName, principal);

标签: c#authenticationiisasp.net-core

解决方案


推荐阅读