Link to home
Start Free TrialLog in
Avatar of TheCommunicator
TheCommunicatorFlag for United States of America

asked on

Cookie expiration fails

I have this line of code:
Request.Cookies["CurrentUser"].Expires = DateTime.Now.AddMinutes(20);

Open in new window



I suppose it has to add 20 minutes to the cookie which resides on the client.

Now, if I do something like this:

RCookie = Request.Cookies["CurrentUser"];

Open in new window


what should be  Rcookie's expiration? Ithought it would be something 20 minutes after from when I saved "Currentuser" cookie.

BUT
it shows me {1/1/0001 12:00:00 AM} what does that even mean?
ASKER CERTIFIED SOLUTION
Avatar of Carlos Villegas
Carlos Villegas
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you change the value of a cookie, the expiration date is set back to the 01-Jan-0001 12:00:00 AM.  Check the link below.  Check the Cookie Expiration section.

http://www.codeproject.com/KB/aspnet/aspnetcookies.aspx
 
I hope this helps.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of SAMIR BHOGAYTA
SAMIR BHOGAYTA
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TheCommunicator

ASKER

Ok Guys, may be my little lack of Web architecture also playing a major role here but just for the sake of the question when I do something like this:

HttpCookie cookieCurrentUser = Request.Cookies["CurrentUser"]

Open in new window


Server is requesting a Cookie with the name "CurrentUser" and using it to instantiate a local instance called cookieCurrentUser. Right?

So, would that be a correct statement that cookieCurrentUser gets everything from the client except expiration date?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To conclude: When server asks for Cookie, Web Browser is not capable of sending Expiration date/time, it only sends name/value at this moment. and when Cookie is received by the server, it sets default to some 01/01/001 date.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks :).