title: How to synchronize lifetime of forms authentication cookie and Asp.Net Session?
body: <p>I am building an ASP.NET web site that uses <code>FormsAuthentication</code> and a standard Session mechanism with configuration like:</p>
  
  <pre><code>&lt;authentication mode="Forms"&gt;
      &lt;forms cookieless="UseCookies" name=".MyAppAuth" loginUrl="~\Login.aspx" timeout="20"/&gt;
  &lt;/authentication&gt;
  ...
  &lt;sessionState timeout="20" cookieless="UseCookies" /&gt;
  </code></pre>
  
  <p>It seems that the lifetime of an authentication cookie is not equal to the lifetime of the user Session.
  So ASP.NET doesn't guarantee that</p>
  
  <ol>
  <li><p>Session terminates when user logout,</p></li>
  <li><p>Session doesn't terminates before user logout.</p></li>
  </ol>
  
  <p>Is there a way to customize <code>FormsAuthentication</code> or\and the Session State mechanism to Reach these goals?</p>