我'm trying to get a persistent connection so the users only have to use their password once. I'使用了这个文档:https://docs.microsoft.com/en-us/aspnet/core/security/authentication/cookie?tabs=aspnetcore2x但是用户在一段时间后仍然断开连接 .
await HttpContext.SignInAsync(
CookieAuthenticationDefaults.AuthenticationScheme,
principal,
new AuthenticationProperties
{
IsPersistent = true
});
我该怎么做才能获得真正持久的连接?
1 回答
根据文档,IsPersistent授予的持久性仅仅意味着认证将通过浏览会话持续存在(即,即使在浏览器关闭时也会保留) . 您需要Persistence的组合并设置cookie的到期时间 . 可以使用ExpireTimeSpan选项通过CookieAuthenticationOptions (MSDN)设置cookie的到期时间 .
如果没有持久性,可以使用AuthenticationOptions中的ExpiresUtc选项设置身份验证的到期时间,