在ExpireTimeSpan上自动注销网页Aurelia MVC5身份验证

时间:2018-10-11 19:32:42

标签: javascript c# authentication logoff cookie-authentication

我有一个带有Aurelia SPA的MVC5“ .Net Framework 4.6.2” Web服务器,运行良好。我想要做的是将身份验证扩展为在一段时间不活动后自动注销用户。

使用CookieAuthenticationOptions设置如下

LoginPath = new PathString("/Account/Login"),
SlidingExpiration=true,
ExpireTimeSpan=TimeSpan.FromMinutes(2)

发生的情况是,达到ExpireTimeSpan后,不再对用户进行身份验证,这是预期的,但是不会自动将其重定向到我需要执行的Loginpath。

我具有基本的启动类,如下所示,但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);
    }
}

有人可以告诉我我在这里想念什么吗?

提前谢谢!

0 个答案:

没有答案