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