Question

We're supporting legacy code that is dropping a cookie and setting the expiration to DateTime.MaxValue:

HttpCookie cookie = new HttpCookie(cookieName, value);
cookie.Expires = DateTime.MaxValue;

It seems that on some browsers (which we are not logging), this cookie expires immediately--or may not even be getting dropped. According to MSDN, DateTime.MaxValue is December 31, 9999. Are there any browser-related issues with setting a cookie expiration to this date?

The correct answer would be to change the expiration date, but at this point, we can't change production code.

Was it helpful?

Solution

If I had to randomly guess why it's not working, I would say it has something to do with Unix epoch time. This value will technically overflow (on 32-bit machines) after January 19, 2038 at 3:14:07 AM GMT - so the next second after this would be interpreted as January 1, 1970 0:00:01 AM GMT.

It's possible that the future time you've supplied is actually converted into a past time.

Again, this is a complete guess and hopefully I can test it soon when VWD Express 2008 is downloaded on my home machine.

Edit:

Searching for this issue, I have found a similar error:

http://framework.zend.com/issues/browse/ZF-5690

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top