Hi,
I'm having a strange problem with setting a cookie's expiration date. The
relevant code is as follows:
HttpCookie hc = new HttpCookie("MyCookie");
hc.Values.Add("UserName", tbUserName.Text);
hc.Expires = DateTime.Now.AddDays(30);
Response.AppendCookie(hc);
As you can see it's just a simple cookie storing one value. But when I check
its expiration date (by writing it to an ASP:Label control on the ASPX
page), DateTime.MinValue (i.e., 1/1/0001 12:00:00 AM) is returned every
time. I've researched this extensively online and in MS's documentation and
found nothing addressing this problem very clearly. I have read that an
expiration date of DateTime.MinValue means the cookie will never expire. I
suspect it has something to do with the session cookie ASP.NET sends to the
client automatically (the one containing ASP.NET_SessionId); maybe I'm
inadvertantly obtaining that cookie's expiration date, which would be "never
expires" because it's just a session cookie, as opposed to my persistent
cookie. But the code I use to obtain the expiration date is
Request.Cookies["MyCookie"].Expires.ToString(), which seems to refer to my
cookie to me.
Does anyone have any ideas?
Thanks very much,
Jim Kelly 3 12865
"Jim Kelly" <cr*******@yahoo.com> wrote in
news:-z********************@comcast.com: Hi,
I'm having a strange problem with setting a cookie's expiration date. The relevant code is as follows:
HttpCookie hc = new HttpCookie("MyCookie"); hc.Values.Add("UserName", tbUserName.Text); hc.Expires = DateTime.Now.AddDays(30); Response.AppendCookie(hc);
As you can see it's just a simple cookie storing one value. But when I check its expiration date (by writing it to an ASP:Label control on the ASPX page), DateTime.MinValue (i.e., 1/1/0001 12:00:00 AM) is returned every time. I've researched this extensively online and in MS's documentation and found nothing addressing this problem very clearly. I have read that an expiration date of DateTime.MinValue means the cookie will never expire. I suspect it has something to do with the session cookie ASP.NET sends to the client automatically (the one containing ASP.NET_SessionId); maybe I'm inadvertantly obtaining that cookie's expiration date, which would be "never expires" because it's just a session cookie, as opposed to my persistent cookie. But the code I use to obtain the expiration date is Request.Cookies["MyCookie"].Expires.ToString(), which seems to refer to my cookie to me.
Does anyone have any ideas?
Jim,
The browser never sends the cookie's expiration date back to the
server. This isn't generally a problem, since the browser won't send
the cookie to the server if the cookie has expired.
Here's an excellent article about cookies and .Net: http://www.codeproject.com/aspnet/AspNetCookies.asp
Hope this helps.
Chris.
-------------
C.R. Timmons Consulting, Inc. http://www.crtimmonsinc.com/
Chris,
Thanks. It figures that the one article that answers my question in one
sentence is the one that didn't turn up in my search!
Jim
"Chris R. Timmons" <crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote in message
news:Xn**********************************@207.46.2 48.16... "Jim Kelly" <cr*******@yahoo.com> wrote in news:-z********************@comcast.com:
Hi,
I'm having a strange problem with setting a cookie's expiration date. The relevant code is as follows:
HttpCookie hc = new HttpCookie("MyCookie"); hc.Values.Add("UserName", tbUserName.Text); hc.Expires = DateTime.Now.AddDays(30); Response.AppendCookie(hc);
As you can see it's just a simple cookie storing one value. But when I check its expiration date (by writing it to an ASP:Label control on the ASPX page), DateTime.MinValue (i.e., 1/1/0001 12:00:00 AM) is returned every time. I've researched this extensively online and in MS's documentation and found nothing addressing this problem very clearly. I have read that an expiration date of DateTime.MinValue means the cookie will never expire. I suspect it has something to do with the session cookie ASP.NET sends to the client automatically (the one containing ASP.NET_SessionId); maybe I'm inadvertantly obtaining that cookie's expiration date, which would be "never expires" because it's just a session cookie, as opposed to my persistent cookie. But the code I use to obtain the expiration date is Request.Cookies["MyCookie"].Expires.ToString(), which seems to refer to my cookie to me.
Does anyone have any ideas?
Jim,
The browser never sends the cookie's expiration date back to the server. This isn't generally a problem, since the browser won't send the cookie to the server if the cookie has expired.
Here's an excellent article about cookies and .Net:
http://www.codeproject.com/aspnet/AspNetCookies.asp
Hope this helps.
Chris. ------------- C.R. Timmons Consulting, Inc. http://www.crtimmonsinc.com/
Jim,
I am running into the same problem and did read the article mentioned
below. Still don't see what is going on. The code I am using is:
BECartCookie = new HttpCookie("BECart");
BECartCookie.Value = CartID.ToString();
BECartCookie.Path = "/";
BECartCookie.Expires = dNow.AddHours(48);
Response.Cookies.Set(BECartCookie);
Is there anything wrong with this? Every time I look at the cookie it
returns the "beginning of time" expiration date.
Thanks,
Mike
On Sat, 2 Aug 2003 08:51:54 -0600, "Jim Kelly" <cr*******@yahoo.com>
wrote: Chris,
Thanks. It figures that the one article that answers my question in one sentence is the one that didn't turn up in my search!
Jim
"Chris R. Timmons" <crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote in message news:Xn**********************************@207.46. 248.16... "Jim Kelly" <cr*******@yahoo.com> wrote in news:-z********************@comcast.com:
> Hi, > > I'm having a strange problem with setting a cookie's expiration > date. The relevant code is as follows: > > HttpCookie hc = new HttpCookie("MyCookie"); > hc.Values.Add("UserName", tbUserName.Text); > hc.Expires = DateTime.Now.AddDays(30); > Response.AppendCookie(hc); > > As you can see it's just a simple cookie storing one value. But > when I check its expiration date (by writing it to an ASP:Label > control on the ASPX page), DateTime.MinValue (i.e., 1/1/0001 > 12:00:00 AM) is returned every time. I've researched this > extensively online and in MS's documentation and found nothing > addressing this problem very clearly. I have read that an > expiration date of DateTime.MinValue means the cookie will never > expire. I suspect it has something to do with the session cookie > ASP.NET sends to the client automatically (the one containing > ASP.NET_SessionId); maybe I'm inadvertantly obtaining that > cookie's expiration date, which would be "never expires" because > it's just a session cookie, as opposed to my persistent cookie. > But the code I use to obtain the expiration date is > Request.Cookies["MyCookie"].Expires.ToString(), which seems to > refer to my cookie to me. > > Does anyone have any ideas?
Jim,
The browser never sends the cookie's expiration date back to the server. This isn't generally a problem, since the browser won't send the cookie to the server if the cookie has expired.
Here's an excellent article about cookies and .Net:
http://www.codeproject.com/aspnet/AspNetCookies.asp
Hope this helps.
Chris. ------------- C.R. Timmons Consulting, Inc. http://www.crtimmonsinc.com/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Derek Fountain |
last post by:
I set my session parameter so the session is a few minutes long, and if the
user goes inactive for that period the session expires. Two questions:
1) What mechanism actually expires the session?...
|
by: Brian Burgess |
last post by:
Hi all,
Anyone know if this is possible? If so, on which page would the
cookie be? .. On the page calling a function defined in the include
file?
thanks in advance..
-BB
|
by: benny |
last post by:
Hi,
I used following procedure to created the cookies:-
FormsAuthentication.RedirectFromLoginPage(IntToStr(BizCustomerID),
wchkRememberLogin.Checked);
I found that the setting on web.config...
|
by: Joey Powell |
last post by:
This message was originally posted to the aspnet.security newsgroup,
but no one there has ever heard of this before. That is why I am
posting this message here, so that more people will see it...
...
|
by: Mike |
last post by:
I have a web application that the forms authentication cookie is not expiring correctly. When I look at the trace information of a newly requested page after the session and forms authentication have...
|
by: Goober |
last post by:
I have an application where we have a limited number of users and a set
requirement for web access. An app that I have inherited uses cookies to
set certain values (i.e. what would correspond to...
|
by: pv_kannan |
last post by:
I recently found out that my authentication cookies are not expiring
even though I have set the persist property to false. As a result,
users are able to access the secure websites with indifferent...
|
by: serge calderara |
last post by:
Dear all,
I try to make some test on how to use basic cookie but get some trouble in
the sens that I was not able to read back previous cretaed cookies.
In page_load event I have the following...
|
by: chrisx |
last post by:
I get java errors in IE with this cookie, any idea why? Also how do I name the cookie and set it to expire in 20 min. I am not that familiar with expiring cookies. Any help is appreciated.
...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |