我有一个带有 Aurelia SPA 的 MVC5“.Net Framework 4.6.2”网络服务器,它工作得非常好。我想要做的是扩展我的身份验证以在一段时间不活动后自动注销用户。
使用 CookieAuthenticationOptions 设置如下
LoginPath = new PathString("/Account/Login"),
SlidingExpiration=true,
ExpireTimeSpan=TimeSpan.FromMinutes(2)
发生的情况是,在达到 ExpireTimeSpan 后,用户不再经过身份验证,这是预期的,但他们不会自动重定向到我需要发生的登录路径。
我有如下所示的基本启动类,但 cookie“.AspNet.ApplicationCookie”永不过期,它设置为 1969-12-31T23:59:59.000Z。
public partial class Startup
{
public void ConfigureAuth(IAppBuilder app)
{
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
app.CreatePerOwinContext<ApplicationRoleManager>(ApplicationRoleManager.Create);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
//ExpireTimeSpan = TimeSpan.FromMinutes(120),
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(15),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));
app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
}
}
有人可以告诉我我在这里缺少什么吗?
先感谢您!