title: FormsAuthenticationTicket expiration
body: <p>I have been searching the web and found many odd answers and i've tried almost all of them.
  My problem is this. My login page contains:</p>
  
  <pre><code>FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, userName, DateTime.Now, DateTime.Now.AddMinutes(min), persistCookie, userid.ToString());
  string encTicket = FormsAuthentication.Encrypt(ticket);
  HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
  cookie.Expires = ticket.Expiration;
  Response.Cookies.Add(cookie);
  
  FormsAuthentication.RedirectFromLoginPage(userName, persistCookie);
  </code></pre>
  
  <p>Now the min value is per user based and can be set individually, so is persistCookie.</p>
  
  <p>After what i understand this code should result in the possibillity of overriding the  default values in web.config. Which should be 30 minutes.</p>
  
  <pre><code>&lt;authentication mode="Forms"&gt;
    &lt;forms loginUrl="~/Default/default.aspx" defaultUrl="~/User/UserMain.aspx"/&gt;
  &lt;/authentication&gt;
  </code></pre>
  
  <p>min is currenlty set to 120, and persistCookie is set too true. When i log in i get timeout at 30 minutes. (Not session, so somewhere expiration date is set, because if it was not set the cookie should be session based, also i do not get 120 minutes which is kind of the deal here)</p>
  
  <p>My question, for simplifying it, is how do i get the value 'min' to be the expiry date of the cookie?</p>
  
  <p>This might turn out too be a simple thing but i am currently totally stuck so any help would be appriciated.</p>
  
  <p>EDIT:
  I changed the login logic to this:</p>
  
  <pre><code>FormsAuthenticationTicket fat = new FormsAuthenticationTicket(1, userName, DateTime.Now, DateTime.Now.AddMinutes(min), persistCookie, userid.ToString());
  string encTicket = FormsAuthentication.Encrypt(fat);
  Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket) { Expires = fat.Expiration });
  Response.Redirect(FormsAuthentication.GetRedirectUrl(userName, false));
  </code></pre>
  
  <p>And now it works. But i cant seem to figure out why this would work, and not the previous one.
  Ticket creation is the same, the only difference is that i add Expires property of the HttpCookie when creating the HttpCookie, not after the object is made. </p>
  
  <p>If anybody has a good explanation i am all ears! :)</p>