How IsPersistent works in OWIN Cookie authentication

Persistent cookies will be saved as files in the browser folders until they either expire or manually deleted. This will cause the cookie to persist even if you close the browser.

If IsPersistent is set to false, the browser will acquire session cookie which gets cleared when the browser is closed.

Now the reason session cookie wont clear after restarting the browser is because of chrome default settings. To fix it go to chrome settings -> advanced, and uncheck Continue running background apps when Google Chrome is closed under System section.


public void Configuration(IAppBuilder app)
{
    //Some Code
    app.UseCookieAuthentication(GetCookieAuthenticationOptions());
    //Some Code
}

private static CookieAuthenticationOptions GetCookieAuthenticationOptions()
{
    var options  = new CookieAuthenticationOptions();
    {
        CookieName = "AuthCookie",  //Some cookie settings here
    };
    var provider = (CookieAuthenticationProvider)options.Provider;
    provider.OnResponseSignIn = (context) => 
    {
        context.Properties.IsPersistent = true;
        context.Properties.ExpiresUtc = DateTimeOffset.UtcNow.AddHours(24);
    };
    return options;
}