In some button click event:
foreach (HttpCookie cookie
in Request.Cookies)
{
cookie.Expires = DateTime.Now;
}
Say I am in PST as a client and the server is EST. Would my cookies expire now (percievable on next request) or in 3 hours?
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
In some button click event:
foreach (HttpCookie cookie
in Request.Cookies)
{
cookie.Expires = DateTime.Now;
}
Say I am in PST as a client and the server is EST. Would my cookies expire now (percievable on next request) or in 3 hours?
Pick a date that's years before Now().
The time in the cookie would be in GMT, so you also wouldn't have the issue with time zones or winter time, but if you really want to expire it (time on server and time on client can be slightly off) expire it with:
cookie.Expires = DateTime.Now.AddYears(-1);
PeterF wrote:The time in the cookie would be in GMT, so you also wouldn't have the issue with time zones or winter time, but if you really want to expire it (time on server and time on client can be slightly off) expire it with:
cookie.Expires = DateTime.Now.AddYears(-1);
The help text indicates that what you have should do it.![]()
http://msdn2.microsoft.com/en-us/library/system.web.httpcookie.expires.aspx
Yeah it seems to be a situation of do what I say not as I do (from documentation):
The header is actually sent as a text representation of the date and for the cookie to be valid, it must be in the form:
DAY, DD-MMM-YYYY HH:MM:SS GMT
Since the function you are using takes care of the conversion from a DateTime object to this text, I would hope it would to the conversion for you.
I will be testing it as soon as I get VWD Express 2008 installed. ![]()
odujosh wrote:
How would you figure out time zone of DateTime. How to adjust for GMT? I am curious about a more precise answer if anyone has one.
odujosh,
I just ran a test that shows that the conversion is made from server time zone to client time zone. However, if the client time is off by a few minutes, then the cookie can hang around for a few, or die a few minutes too soon. The source code for the test is
in the Sandbox.
For absolute accuracy, you would need nab the client time and time zone, then convert the client time to the server time zone.
gl...
let me know if you nab the client time and time zone.
btw, you could just store the server time in a cookie and check for expiration yourself.
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.