Asp.net核心持久身份验证-自定义Cookie身份验证 [英] Asp.net Core Persistent Authentication - Custom Cookie Authentication

查看:135
本文介绍了Asp.net核心持久身份验证-自定义Cookie身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试建立持久连接,因此用户只需要使用一次密码即可.我使用过此文档: https://docs.microsoft.com/zh-cn/aspnet/core/security/authentication/cookie?tabs=aspnetcore2x ,但一段时间后用户仍会断开连接.

I'm trying to get a persistent connection so the users only have to use their password once. I've used this doc: https://docs.microsoft.com/en-us/aspnet/core/security/authentication/cookie?tabs=aspnetcore2x but the users still get disconnected after a while.

await HttpContext.SignInAsync(
                    CookieAuthenticationDefaults.AuthenticationScheme,
                    principal,
                    new AuthenticationProperties
                    {
                        IsPersistent = true
                    });

我该怎么做才能获得真正持久的连接?

What can I do to get a really persistent connection ?

推荐答案

根据文档,IsPersistent授予的持久性仅意味着暗示身份验证将通过浏览会话持久化(也就是说,即使在浏览器已关闭).您需要结合Persistence 来设置cookie的到期时间.可以通过设置cookie的过期时间.Cookie身份验证选项(MSDN),使用 ExpireTimeSpan 选项.

The persistence granted by IsPersistent is, according to the docs, only meant to imply that the authentication will persist through browsing sessions (that is, it is kept even when the browser is closed). You need a combination of Persistence and to set an expiration time for the cookie. The expiration of the cookie can be set via the CookieAuthenticationOptions (MSDN), using the ExpireTimeSpan option.

在没有持久性的情况下,可以使用AuthenticationOptions中的 ExpiresUtc 选项设置身份验证的有效期,

Without persistence, expiration of the authentication can be set using the ExpiresUtc option in AuthenticationOptions,

这篇关于Asp.net核心持久身份验证-自定义Cookie身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆