加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-core – 如何在ASP.NET Core中设置cookie validateInter

发布时间:2020-12-16 07:02:12 所属栏目:asp.Net 来源:网络整理
导读:我正在尝试为使用ASP.NET Identity 3的ASP.NET 5 RC1应用程序设置validateInterval 我试图在this答案中实现代码. 有很多代码样本,如this answer,但似乎它在ASP.NET 5 RC1中无效 app.UseCookieAuthentication(new CookieAuthenticationOptions { Provider = n
我正在尝试为使用ASP.NET Identity 3的ASP.NET 5 RC1应用程序设置validateInterval

我试图在this答案中实现代码.

有很多代码样本,如this answer,但似乎它在ASP.NET 5 RC1中无效

app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            Provider = new CookieAuthenticationProvider
            {
                OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager,ApplicationUser>(
        validateInterval: TimeSpan.FromMinutes(15)
            },ExpireTimeSpan = TimeSpan.FromMinutes(30)
        });

如果我尝试在ASP.NET 5 RC1中使用上面的代码示例,我不能这样做

Provider不是CookieAuthenticationOptions的属性
并且Visual Studio无法通过其灯泡选项在任何命名空间中找到CookieAuthenticationProvider.

如何在ASP.NET 5 RC1中设置validateInterval?

解决方法

验证间隔在IdentityOptions中设置:

services.AddIdentity<AppUser,AppRole>(options =>
{
    options.SecurityStampValidationInterval = TimeSpan.FromMinutes(15);
}

您可以使用CookieAuthenticationEvents附加到验证事件:

app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
    Events = new CookieAuthenticationEvents()
    {
        OnValidatePrincipal = context =>
        {
            Microsoft.AspNet.Identity.SecurityStampValidator.ValidatePrincipalAsync(context);
            return Task.FromResult(0);
        },},ExpireTimeSpan = TimeSpan.FromMinutes(30)
});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读