我正在尝试为使用ASP.NET Identity 3的ASP.NET 5 RC1应用程序设置validateInterval
有很多代码样本,如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) });
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。