0

I'm using ASP.Net MVC 5 and Identity. In Startup.Auth class I have this method:

  public void ConfigureAuth(IAppBuilder app)
    {


        // important to register UserManager creation delegate. Won't work without it
        app.CreatePerOwinContext(DatabaseContext.Create);
        app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);



        // Enable the application to use a cookie to store information for the signed in user
        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Account/Login"),
            Provider = new CookieAuthenticationProvider
            {
                // Enables the application to validate the security stamp when the user logs in.
                // This is a security feature which is used when you change a password or add an external login to your account.  
                OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, User>(
                    validateInterval: TimeSpan.FromDays(365),
                    regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))

            },
            ExpireTimeSpan = TimeSpan.FromDays(365),


        });
        // Use a cookie to temporarily store information about a user logging in with a third party login provider
        app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);


    }

For some reason when I exit Chrome cookie is being persisted, but when I exit IE or Firefox cookie is deleted (and this doesn't happen with other pages). How can I fix this ?

hyperN
  • 2,674
  • 9
  • 54
  • 92
  • The reason it seems to work in Chrome is that chrome caches the page when you close and re-open it... so it restores non-persistent cookies – Erik Funkenbusch Nov 05 '14 at 17:26
  • @ErikFunkenbusch You've marked my question as duplicate, but problem with Jenkie's code is that he had line: validateInterval: TimeSpan.FromMinutes(0) ... and I have validateInterval: TimeSpan.FromDays(365), so we don't have same issue – hyperN Nov 05 '14 at 17:29
  • 1
    Reread it. "The issue is with a bug in the OnValidateIdentity which when regenerating the cookie currently always sets IsPersistent to false (even if the original cookie was persistent). " It doesn't matter if you're setting it to 0 or 365, you're regenerating the cookie. – Erik Funkenbusch Nov 05 '14 at 17:32
  • 1
    You can try this approach.. http://stackoverflow.com/questions/23983726/expiretimespan-ignored-after-regenerateidentity-validateinterval-duration-in-m – Erik Funkenbusch Nov 05 '14 at 17:36

0 Answers0