Different ASP.NET Identity cookie expire time in some browsers

581 Views Asked by At

I've encountered a strange problem in ASP.NET Identity 2. I've used Cookie Authentication in ASP.NET Identity 2.

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, ApplicationUser>(
                    validateInterval: TimeSpan.FromMinutes(30),
                    regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
            },
            SlidingExpiration = true,
            ExpireTimeSpan = TimeSpan.FromMinutes(60)
        });  

Every thing is OK except cookie expire time in some browsers. I know I have to use CookieAuthenticationOptions.ExpireTimespan for setting the time that cookie is valid and I set it to an hour (ExpireTimeSpan = TimeSpan.FromMinutes(60)). In some browsers it works properly, but in some other browsers it expires every five minutes and users logout and have to login again in every 5 minutes!

If it is a problem in my project or IIS settings, why in some browsers it works fine without any problems? I even checked the versions of browsers and they were the same! I Even guessed It may be because of a plug-in installed on those browsers, so I uninstalled that browser and installed it again! But the problem was still there.

The interesting point is that in one system it was OK on chrome but in IE and Firefox the problem was exist. Or in another computer it was OK on Firefox but when the Firefox updated the problem appeared!

I'm really confused. Can anyone tell me how to solve this problem and why it is only in some browsers?

0

There are 0 best solutions below