如何在ASP.NET Core中设置cookie validateInterval? [英] How to set the cookie validateInterval in ASP.NET Core?
问题描述
我正在尝试为使用ASP.NET Identity 3
我正在尝试在此中实现代码答案.
I am trying to implement the code in this answer.
有许多代码示例,例如此答案,但在ASP.NET 5 RC1中似乎无效
there are many code sample like this answer but it seems it isn't valid in 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
中使用上面的代码示例,我将无法做到
If I try use the above code example in ASP.NET 5 RC1
I can't as
Provider
不是CookieAuthenticationOptions
的属性
并且Visual Studio无法通过其灯泡选项在任何命名空间中找到CookieAuthenticationProvider
.
Provider
is not a property of CookieAuthenticationOptions
and Visual studio cannot locate CookieAuthenticationProvider
in any namespace via its lightbulb options.
如何在ASP.NET 5 RC1
中设置validateInterval
?
推荐答案
验证间隔在IdentityOptions中设置:
The validation interval is set in IdentityOptions:
services.AddIdentity<AppUser, AppRole>(options =>
{
options.SecurityStampValidationInterval = TimeSpan.FromMinutes(15);
}
您可以使用CookieAuthenticationEvents附加到验证事件:
You can attach to the validation event using the CookieAuthenticationEvents:
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
Events = new CookieAuthenticationEvents()
{
OnValidatePrincipal = context =>
{
Microsoft.AspNet.Identity.SecurityStampValidator.ValidatePrincipalAsync(context);
return Task.FromResult(0);
},
},
ExpireTimeSpan = TimeSpan.FromMinutes(30)
});
这篇关于如何在ASP.NET Core中设置cookie validateInterval?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!