Search code examples
c#asp.net-coreasp.net-identity

ASP.NET Core Identity session expires sooner than it is configured to happen


So in my application I've configured the identity as:

services.ConfigureApplicationCookie(cfg =>
            {
                cfg.Cookie.Name = "application_ms_state";
                cfg.Cookie.Expiration = TimeSpan.FromDays(1);
                cfg.SlidingExpiration = true;
            });

but the expiration happens in almost 20 minutes.could anyone shed some light on this?


Solution

  • Read the doc comments. https://github.com/aspnet/Security/blob/a53bf093a7d86b35e019c80515c92d7626982325/src/Microsoft.AspNetCore.Authentication.Cookies/CookieAuthenticationOptions.cs#L147 ExpiresTimeSpan and Expiration control different things. ExpiresTimeSpan is the one used for sliding expiration.