473,396 Members | 1,849 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

cookie expiry date 01/01/0001

Ray
Below is the code to save the cookie and set the expiry date of the cooki

Response.Cookies["demo"].Value ="Hello"
DateTime dt = DateTime.Now
TimeSpan ts = new TimeSpan(0,0,10,0)
Response.Cookies ["demo"].Expires = dt.Add(ts);

Below is the code to retrieve the stored cookie

if (!Page.IsPostBack)
HttpCookie dcookie = Request.Cookies["demo"]
if (dcookie != null)
urlevel.Text = dcookie.Values["level"]
urname.Text = dcookie.Values["user"];
daysx.Text = Convert.ToString(Request.Cookies["demo"].Expires)

els
Response.Redirect ("haha.htm")
When I display the Response.Cookies ["demo"].Expires = dt.Add(ts); it returns the current date + 10 minute
But the days.Text returns 01/01/0001. Why? Please help Thanks

Ra

Jul 21 '05 #1
6 3774
=?Utf-8?B?UmF5?= <an*******@discussions.microsoft.com> wrote in
news:E7**********************************@microsof t.com:
Below is the code to save the cookie and set the expiry date of
the cookie

Response.Cookies["demo"].Value ="Hello";
DateTime dt = DateTime.Now;
TimeSpan ts = new TimeSpan(0,0,10,0);
Response.Cookies ["demo"].Expires = dt.Add(ts);

Below is the code to retrieve the stored cookie.

if (!Page.IsPostBack) {
HttpCookie dcookie = Request.Cookies["demo"];
if (dcookie != null) {
urlevel.Text = dcookie.Values["level"];
urname.Text = dcookie.Values["user"];
daysx.Text =
Convert.ToString(Request.Cookies["demo"].Expires);
}
else
Response.Redirect ("haha.htm");
}

When I display the Response.Cookies ["demo"].Expires =
dt.Add(ts); it returns the current date + 10 minutes But the
days.Text returns 01/01/0001. Why? Please help Thanks.


Ray,

http://www.codeproject.com/aspnet/AspNetCookies.asp
Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Jul 21 '05 #2
=?Utf-8?B?UmF5?= <an*******@discussions.microsoft.com> wrote in
news:E7**********************************@microsof t.com:
Below is the code to save the cookie and set the expiry date of
the cookie

Response.Cookies["demo"].Value ="Hello";
DateTime dt = DateTime.Now;
TimeSpan ts = new TimeSpan(0,0,10,0);
Response.Cookies ["demo"].Expires = dt.Add(ts);

Below is the code to retrieve the stored cookie.

if (!Page.IsPostBack) {
HttpCookie dcookie = Request.Cookies["demo"];
if (dcookie != null) {
urlevel.Text = dcookie.Values["level"];
urname.Text = dcookie.Values["user"];
daysx.Text =
Convert.ToString(Request.Cookies["demo"].Expires);
}
else
Response.Redirect ("haha.htm");
}

When I display the Response.Cookies ["demo"].Expires =
dt.Add(ts); it returns the current date + 10 minutes But the
days.Text returns 01/01/0001. Why? Please help Thanks.


Ray,

http://www.codeproject.com/aspnet/AspNetCookies.asp
Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Jul 21 '05 #3
Ray
HI, Chris

I had tried that
It still gives me 01/01/0001 when I displayed the expiry date from the cookie collection
Jul 21 '05 #4
Ray
HI, Chris

I had tried that
It still gives me 01/01/0001 when I displayed the expiry date from the cookie collection
Jul 21 '05 #5
=?Utf-8?B?UmF5?= <an*******@discussions.microsoft.com> wrote in
news:48**********************************@microsof t.com:
HI, Chris:

I had tried that.
It still gives me 01/01/0001 when I displayed the expiry date
from the cookie collection


Ray,

Exactly. The browser will not send the expiration date of the cookie
back to the server (I don't know why). So trying to read
Request.Cookies["demo"].Expires will never work.

If you only need to know if the cookie has expired or not, the
browser takes care of that by not sending the cookie if it has
expired. However, if you need to know how much time is remaining
before the cookie expires, then you probably need to store another
expiration date in a cookie value so you can read it:

Response.Cookies["demo].Values["expiration_date"] = ...

and

daysx.Text = Convert.ToString(
Request.Cookies["demo"].Values["expiration_date"]);

Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Jul 21 '05 #6
=?Utf-8?B?UmF5?= <an*******@discussions.microsoft.com> wrote in
news:48**********************************@microsof t.com:
HI, Chris:

I had tried that.
It still gives me 01/01/0001 when I displayed the expiry date
from the cookie collection


Ray,

Exactly. The browser will not send the expiration date of the cookie
back to the server (I don't know why). So trying to read
Request.Cookies["demo"].Expires will never work.

If you only need to know if the cookie has expired or not, the
browser takes care of that by not sending the cookie if it has
expired. However, if you need to know how much time is remaining
before the cookie expires, then you probably need to store another
expiration date in a cookie value so you can read it:

Response.Cookies["demo].Values["expiration_date"] = ...

and

daysx.Text = Convert.ToString(
Request.Cookies["demo"].Values["expiration_date"]);

Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Jul 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Vince C. | last post by:
Hi all. I'm trying to set a cookie expiry date but my script is JS (JavaScript). I've tried Response.Cookies("Test").Expires = Date(); Response.Cookies("Test").Expires =...
1
by: Hardeep Rakhra | last post by:
Hi i have a snippet of JS that i want to change so that the cookie it creates lasts only 48 hours. (or any other length of time i decide, but 48hours seems right for now) Only thing i can't...
7
by: What-a-Tool | last post by:
How does the expire date work setting it server side with asp. I know with javascript setting it client side it will be set to the clients local time, and therefore expire when the clients local...
3
by: HorseGeek | last post by:
I can't find a cookie that my code is writing. The behavior of my webpages indicates that the cookie IS being written SOMEPLACE. However, I can't find it. My client does not want the code going...
5
by: brettr | last post by:
When I reference document.cookie, there is a long string of key=value; pairs listed. I may have 100 hundred cookies on my hard drive. However, most only have one key=value pair. Does the...
4
by: Aki | last post by:
Hi, I have a problem with writing cookies in IE. The code works fine in Netscape 7.2, Opera 8 and Firefox 1.04. In IE 6 the cookie isn't written. I run WinXP SP2. I'm trying to show a...
9
by: Marco Krechting | last post by:
Hi All, I have a page with a list of hyperlinks. I want to save information in a cookie about the fact that I entered an hyperlink or not. When I click one of the hyperlinks I want this stored...
6
by: Ray | last post by:
Below is the code to save the cookie and set the expiry date of the cooki Response.Cookies.Value ="Hello" DateTime dt = DateTime.Now TimeSpan ts = new TimeSpan(0,0,10,0) Response.Cookies...
1
by: Milsnips | last post by:
Hi there, I don't know why its not working for me, here is the code I am using: Response.Cookies.Value = "Cookie is set"; Response.Cookies.Expires = DateTime.Now.AddYears(30);...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.