CookieAuthenticationOptions, ExpireTimeSpan does not work

前端 未结 2 1477
深忆病人
深忆病人 2021-02-07 01:02

I have the following code:

    public void ConfigureAuth(IAppBuilder app)
    {
        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            


        
相关标签:
2条回答
  • 2021-02-07 01:34

    It does expire.

    Make sure you do not have any background ajax activity as it extends the session (SlidingExpiration is true by default).

    Also I had to manually delete the old cookie after I changed ExpireTimeSpan from the default 14 days to a smaller value.

    0 讨论(0)
  • 2021-02-07 01:36

    You must set IsPersistent to true otherwise you don't run code

        ClaimsIdentity claimsIdentity = new ClaimsIdentity(Claims, CookieAuthenticationDefaults.AuthenticationScheme);
    
                    var authProperties = new AuthenticationProperties
                    {
                        IsPersistent = true
    
                    };
    
                    await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity), authProperties);
    
    0 讨论(0)
提交回复
热议问题