Search code examples
asp.net-identity

app.UseCookieAuthentication does not seem to be working for cookiename or expiretimespan


In asp.net 5 + (asp.net identity 3.0) I am trying to rename the cookie and see if I can set the log out value from its default.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { app.UseIdentity();

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {

                CookieName = "MyCookie",
                ExpireTimeSpan = TimeSpan.FromMinutes(1.0),

            });
}

enter image description here

The cookie name is not being renamed to MyCookie and ExpireTimeSpan = TimeSpan.FromMinutes(1.0) is not "logging me out after 1 minute) or setting the . I do get redirected to


Solution

  • It turns out you have to use

     public void ConfigureServices(IServiceCollection services)
            {
    
      services.AddIdentity<ApplicationUser, ApplicationRole>(
                       options => {
    
                           options.Cookies.ApplicationCookieAuthenticationScheme = "MyCookie";
                           options.Cookies.ApplicationCookie.AuthenticationScheme = IdentityCookieOptions.ApplicationCookieAuthenticationType = "MyCookie";
                           options.Cookies.ApplicationCookie.ExpireTimeSpan = TimeSpan.FromSeconds(30.0);
                           options.Cookies.ApplicationCookie.CookieName = "MyCookie";
    
    
                       })
    

    }

    I was using IApplicationBuilder app

      app.UseIdentity().UseCookieAuthentication(
                new CookieAuthenticationOptions
                {
    

    ... ect

    So basically using IServiceCollection AddIdentity fix my issue.