Ope*_* Fx 6 asp.net-core asp.net-core-2.0
我正在尝试获得持久连接,以便用户只需使用密码一次。我使用过这个文档:https://learn.microsoft.com/en-us/aspnet/core/security/authentication/cookie ?tabs=aspnetcore2x 但用户仍然在一段时间后断开连接。
await HttpContext.SignInAsync(
CookieAuthenticationDefaults.AuthenticationScheme,
principal,
new AuthenticationProperties
{
IsPersistent = true
});
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能获得真正持久的连接?
根据文档,IsPersistent 授予的持久性仅意味着身份验证将在浏览会话中持续存在(也就是说,即使浏览器关闭,身份验证也会保留)。您需要持久性和设置 cookie 的过期时间的组合。可以通过CookieAuthenticationOptions (MSDN)使用ExpireTimeSpan选项设置 cookie 的过期时间。
如果没有持久性,可以使用AuthenticationOptions 中的ExpiresUtc选项设置身份验证的过期时间,
| 归档时间: |
|
| 查看次数: |
7949 次 |
| 最近记录: |