ASP.NET Core MVC: setting expiration of identity cookie

前端 未结 6 619
死守一世寂寞
死守一世寂寞 2020-12-04 18:15

In my ASP.NET Core MVC app the lifetime of the authentication cookie is set to \'Session\', so it lasts until I close the browser. I use the default authentication scheme fo

6条回答
  •  被撕碎了的回忆
    2020-12-04 18:24

    For some reason I had the issue when using SignInAsync([..], true) the cookie was never be shown in browser (and properly the login failed):

    So, I tried adding the UTC timezone difference into the TimeSpan of ExpireTimeSpan

    services.AddIdentity(o =>
    {
        // add TimeSpan with 5 minutes plus timezone difference from Utc time
        o.Cookies.ApplicationCookie.ExpireTimeSpan = DateTime.Now.Subtract(DateTime.UtcNow).Add( TimeSpan.FromMinutes(5) );
    
    });
    

    Voila! It worked and the cookie is shown with +5min expiration only in browser.

    PingBack to github.com https://github.com/aspnet/Identity/issues/766#issuecomment-253237576

提交回复
热议问题