How IsPersistent works in OWIN Cookie authentication

前端 未结 3 1107
后悔当初
后悔当初 2020-12-04 19:08

It seems I don\'t understand clearly how IsPersistent in OWIN cookie authentication works, the code below is to use IsPersistent:

v         


        
3条回答
  •  借酒劲吻你
    2020-12-04 19:46

    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;
    }
    

提交回复
热议问题