title: Session timeout before given time
body: <p>I am using form authentication with Asp.Net MVC application as given below:</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>public void SignIn(string userName, bool isCookiePersistent)
          {
  
              FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, userName, DateTime.Now, DateTime.Now.AddDays(14),
                  createPersistentCookie, string.Empty);
  
              HttpCookie authCookie = FormsAuthentication.GetAuthCookie(userName, isCookiePersistent);
              if (authTicket.IsPersistent)
              {
                  authCookie.Expires = authTicket.Expiration;
              }
  
              authCookie.Value = FormsAuthentication.Encrypt(authTicket);
              HttpContext.Current.Response.Cookies.Add(authCookie);
          }
  
  public void SignOut()
          {
              FormsAuthentication.SignOut();
          }
  </code></pre>
  
  <p><strong>Problem:</strong>
  The problem is, if I set form authentication timeout to 4 hours, still my users redirected to login page after half-hour after log in.</p>
  
  <p>I have tried by both including <code>SessionSate</code> OR execluding <code>SessionState</code> in web.config, but noting is happening. Still the problem remain same. Here is my below web.cofig code.</p>
  
  <p><strong>Web.config (without sessionState element)</strong></p>
  
  <pre><code>  &lt;authentication mode="Forms"&gt;
        &lt;forms loginUrl="~/LogOn/LogOn" requireSSL="false" timeout="240" defaultUrl="~/Home/Home" name="__appcookie" path="/" slidingExpiration="true" ticketCompatibilityMode="Framework40" protection="All"&gt;
        &lt;/forms&gt;
      &lt;/authentication&gt;
  </code></pre>
  
  <p><strong>Web.config (WITH sessionState element)</strong></p>
  
  <pre><code>&lt;sessionState timeout="240"&gt;&lt;/sessionState&gt;
   &lt;authentication mode="Forms"&gt;
            &lt;forms loginUrl="~/LogOn/LogOn" requireSSL="false" timeout="240" defaultUrl="~/Home/Home" name="__appcookie" path="/" slidingExpiration="true" ticketCompatibilityMode="Framework40" protection="All"&gt;
            &lt;/forms&gt;
          &lt;/authentication&gt;
  </code></pre>
  
  <p>Could anybody please do let me know that it's really important to include <code>sessionState</code> and <code>sessionTimeout</code> in web.config ? Can't I only use <code>formAuthentication</code> through out my application?</p>
  
  <p>No matter if I use <code>sessionState</code> or NOT, Even only with <code>form authentication</code>, my user redirected to login page after half-hour after logging in application. (BUT I already set 240 minutes as a <code>form authentication timeout</code>). </p>
  
  <p>Could anybody please give me some idea or solution on this.</p>
  
  <p>Thanks in advance!</p>