Smoerble
asked on
How to set Cookie.Expire time?
Hoi all...
I have trouble with the following code:
--------
DateTime dtNow = DateTime.Now;
TimeSpan tsMinute = new TimeSpan(365, 0, 0, 0);
HttpCookie myCookie = new HttpCookie(cookieName);
myCookie.Expires = dtNow + tsMinute;
myCookie["memberID"] = iMemberID.ToString();
myCookie["memberNick"] = sMemberNick;
myCookie["memberPassword"] = sMemberPassword;
this.Response.Cookies.Add( myCookie);
----
Now I check, what the expire time for the cookie is:
----
myCookie = inPage.Request.Cookies[coo kieName];
Response.Write("this cookie expires: "+myCookie.Expires);
----
I always get:
01.01.0001 00:00:00
The idea how to set the cookie is taken from here:
http://www.csharphelp.com/archives/archive179.html
Can someone tell me how I tell my cookie to life for 365 days from now?
Thank you.
I have trouble with the following code:
--------
DateTime dtNow = DateTime.Now;
TimeSpan tsMinute = new TimeSpan(365, 0, 0, 0);
HttpCookie myCookie = new HttpCookie(cookieName);
myCookie.Expires = dtNow + tsMinute;
myCookie["memberID"] = iMemberID.ToString();
myCookie["memberNick"] = sMemberNick;
myCookie["memberPassword"]
this.Response.Cookies.Add(
----
Now I check, what the expire time for the cookie is:
----
myCookie = inPage.Request.Cookies[coo
Response.Write("this cookie expires: "+myCookie.Expires);
----
I always get:
01.01.0001 00:00:00
The idea how to set the cookie is taken from here:
http://www.csharphelp.com/archives/archive179.html
Can someone tell me how I tell my cookie to life for 365 days from now?
Thank you.
ASKER
This contains
---
DateTime dtExpiry = DateTime.Now.AddDays(iDays ToExpire);
Response.Cookies[cookienam e].Expires =dtExpiry;
---
I did that too, same result as above: expire time seems not to be correct.
Any other idea?
---
DateTime dtExpiry = DateTime.Now.AddDays(iDays
Response.Cookies[cookienam
---
I did that too, same result as above: expire time seems not to be correct.
Any other idea?
ASKER
Update:
I checked what the browser says about the cookie:
the date is set correctly... so the question is, why doesn't it display the correct date in my code?
I checked what the browser says about the cookie:
the date is set correctly... so the question is, why doesn't it display the correct date in my code?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, as stated in
http://www.dotnet247.com/247reference/msgs/48/240266.aspx
the cookie does not send back the correct dateTime when using ....Expires.
Thank you.
If anybody has any other idea, please feel free to share ;)
http://www.dotnet247.com/247reference/msgs/48/240266.aspx
the cookie does not send back the correct dateTime when using ....Expires.
Thank you.
If anybody has any other idea, please feel free to share ;)
-Maha