How to set the cookie validateInterval in ASP.NET Core?

As of ASP.NET Core 2.0 you won't be able to set SecurityStampValidationInterval when you AddIdentity.

You'll be able to set the ValidationInterval via SecurityStampValidatorOptions:

        services.Configure<SecurityStampValidatorOptions>(options =>
        {
            options.ValidationInterval = TimeSpan.FromSeconds(10);
        });

P.S: You'll have to AddIdentity first and ConfigureApplicationCookie after.


The validation interval is set in IdentityOptions:

services.AddIdentity<AppUser, AppRole>(options =>
{
    options.SecurityStampValidationInterval = TimeSpan.FromMinutes(15);
}

You can attach to the validation event using the CookieAuthenticationEvents:

app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
    Events = new CookieAuthenticationEvents()
    {
        OnValidatePrincipal = context =>
        {
            Microsoft.AspNet.Identity.SecurityStampValidator.ValidatePrincipalAsync(context);
            return Task.FromResult(0);
        },
    },
    ExpireTimeSpan = TimeSpan.FromMinutes(30)
});