ASP.NET Core身份验证cookie不会过期

时间:2018-11-14 08:39:29

标签: c# authentication iis asp.net-core

在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);

0 个答案:

没有答案