By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,564 Members | 834 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,564 IT Pros & Developers. It's quick & easy.

C#, VS2005, Forms Authentication, can't read cookie after a few hours.

P: 1
Hi Folks,

We are setting cookies on our site so anonymous visitors can save items for a quote:

The cookies are set as follows:
Expand|Select|Wrap|Line Numbers
  1. GUID = System.Guid.NewGuid().ToString();
  2. FormsAuthenticationTicket newTicket = new FormsAuthenticationTicket(
  3. 1,
  4. GUID,
  5. DateTime.Now,
  6. DateTime.Now.Add(new TimeSpan(365, 0, 0, 0)),
  7. true,
  8. String.Empty,
  9. FormsAuthentication.FormsCookiePath);
  10. string encTicket = FormsAuthentication.Encrypt(newTicket); 
  11. HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
  12. authCookie.Expires = DateTime.Now.Add(new TimeSpan(365, 0, 0, 0));
  13. Response.Cookies.Add(authCookie);
  14. Common.Customer.NewAnon(GUID);// Add the Anonymous Customer to the database
the web.config is set to:

Expand|Select|Wrap|Line Numbers
  1. <authentication mode="Forms">
  2. <forms name="MTSGUID" cookieless="UseCookies" protection="All" path="/" timeout="5250000"/>
  3. </authentication>
We have also turned off "Recycle Worker Process" on the server.

Everything works great for a while.

However, after a few hours HttpContext.Current.User.Identity.Name returns null

I don't get it, shouldn't that cookie value be available for a year? When I look at the cookies in Firefox or IE the expiration date is correct.


Nov 14 '07 #1
Share this Question
Share on Google+
1 Reply

Expert 5K+
P: 7,872
Hmm, seems like you're getting "logged out" around when the session ends?

Also, DateTime.Now.AddYears(1); would be a little less messy
Nov 14 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.