title: How to set asp.net Identity cookies expires time
body: <p>I use Asp.Net Identity to control my app's authorization. Now, I need to do this: if the user does not operate in 30 minutes, jump to the login page, when he login does not select "isPersistent" checkbox.
  And, if he selected "isPersistent" checkbox, set the expiration date of cookie for 14 days.
  I try to do this by change the Startup.Auth.cs like this:</p>
  
  <pre><code>public void ConfigureAuth(IAppBuilder app)
  {
      app.UseCookieAuthentication(new CookieAuthenticationOptions
      {
          AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
          LoginPath = new PathString("/Account/Login"),
          SlidingExpiration = true,
          CookieName = WebHelpers.ConstStrings.AUTHCOOKIESNAME
      });
  }
  </code></pre>
  
  <p>and the SignIn code like this:</p>
  
  <pre><code>private async Task SignInAsync(User user, bool isPersistent)
  {
      AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
      var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
      if (isPersistent)
      {
          AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity);
      }
      else
      {
          AuthenticationManager.SignIn(new AuthenticationProperties() { ExpiresUtc = new DateTimeOffset(DateTime.UtcNow.AddMinutes(30)) }, identity);
      }
  }
  </code></pre>
  
  <p>But I found that when the user does not choose isPersistent checkbox, cookies's expiration date is already 'Session', not the current time plus 30 minutes.</p>
  
  <p><a href="https://i.stack.imgur.com/OdClT.png" rel="noreferrer"><img src="https://i.stack.imgur.com/OdClT.png" alt="enter image description here"></a></p>
  
  <p>The cookies status when use the code like after, so the 'remember me' checkbox can't work.:(.</p>
  
  <pre><code>        app.UseCookieAuthentication(new CookieAuthenticationOptions
          {
              AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
              LoginPath = new PathString("/Account/Login"),
              ExpireTimeSpan = TimeSpan.FromMinutes(30),
              SlidingExpiration = true,
              CookieName = WebHelpers.ConstStrings.AUTHCOOKIESNAME
          });
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/irY8b.png" rel="noreferrer"><img src="https://i.stack.imgur.com/irY8b.png" alt="enter image description here"></a></p>