Search code examples
c#asp.net-mvcstartupclaims-based-identity

'CookieAuthenticationProvider' does not contain a definition for 'SlidingExpiration. Claims expiration time


So, I was trying to set expiration time on claims in mvc. That is the code:

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.UseCookieAuthentication(new Microsoft.Owin.Security.Cookies.CookieAuthenticationOptions
        {
            AuthenticationType = "ApplicationCookie",
            LoginPath = new PathString("/Main/LogIn"),
            Provider = new CookieAuthenticationProvider
            {
                ExpireTimeSpan = TimeSpan.FromDays(5),
                SlidingExpiration = true
            }

        });
    }
}

And both, ExpireTimeSpan and SlidingExpiration are underlined with red saying that:'CookieAuthenticationProvider' does not contain a definition for 'SlidingExpiration/ExpireTimeSpan'. Claims expiration time.

I'm new to it and was wondering what am I doing wrong here or what should I do to fix this problem.


Solution

  • They belong to CookieAuthenticationOptions instead of the provider. That should resolve it. CookieAuthenticationOptions

    app.UseCookieAuthentication(new Microsoft.Owin.Security.Cookies.CookieAuthenticationOptions
        {
            AuthenticationType = "ApplicationCookie",
            LoginPath = new PathString("/Main/LogIn"),
            Provider = new CookieAuthenticationProvider(), 
            ExpireTimeSpan = TimeSpan.FromDays(5),
            SlidingExpiration = true          
    
        });