title: Why does my mvc forms authentication with custom entity time out before expected?
body: <p>I am using forms authentication with a custom entity in my app. </p>
  
  <p>The problem I am experiencing is that my authenticated session expires sooner than the 10 minutes that I expect.</p>
  
  <p>I think i may need to renew the cookie each time an authenticated request comes in for that cookie? </p>
  
  <p>Is that the correct thing to do to keep the session alive?</p>
  
  <p>Thanks - code to follow:</p>
  
  <p><strong>Web.Config</strong></p>
  
  <pre><code>&lt;authentication mode="Forms"&gt;
    &lt;forms loginUrl="/Admin/Account/LogOn" slidingExpiration="true" /&gt;
  &lt;/authentication&gt;
  </code></pre>
  
  <p><strong>On sign in</strong></p>
  
  <pre><code>        var identity = new AppIdentity(member.Fullname, member.Id, roles.ToArray());
          FormsAuthentication.SetAuthCookie(identity.ToString(), false);
  
          var myCookie = FormsAuthentication.GetAuthCookie(identity.ToString(), false);
          myCookie.Domain = string.Format(".{0}", "mydomain.com");
          HttpContext.Current.Response.AppendCookie(myCookie);
  </code></pre>
  
  <p><strong>Global.cs</strong></p>
  
  <pre><code>    protected void Application_AuthenticateRequest(object sender, EventArgs e)
      {
          var cookie = Request.Cookies[FormsAuthentication.FormsCookieName];
          var ticket = TryDecryptCookie(cookie);
  
          if (ticket == null)
          {
              return;
          }
  
          var identity = new AppIdentity(ticket);
          var principal = new GenericPrincipal(identity, identity.Roles);
  
          Context.User = principal;
      }
  </code></pre>