473,480 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Expiration date seems not to work

Hiya all,

My buddy and I got a bug with the expiration date of a cookie. When we
want to look out the expiration date, the only thing we've got, it's
01/01/0001.

As we know, when we want to create a persitant cookie, we have to put
a expiration date, otherwise, it will be a session cookie. So here our
code :

HttpCookie cookie = new HttpCookie(m_propertyID);
cookie.Value = m_property;
if (m_temporaryCookie == false)
{
cookie.Expires = DateTime.MaxValue;
}
HttpContext.Current.Response.Cookies.Add(cookie);

And when we want to see the value :

HttpCookie cookie =
HttpContext.Current.Request.Cookies[m_propertyID];

if ( cookie != null)
{
HttpContext.Current.Response.Write(cookie.Expires) ;
}
With that, we've always got the 01/01/0001. If you have any ideas to
help us, let us know.

Btw, sorry for the english typos :)
Nov 17 '05 #1
2 5078
fg*****@neomedia.com (Frederic Gignac) wrote in
news:88**************************@posting.google.c om:
Thank you Chris for the link. Besides I've got a 500 error page,
the Google cache saves me ;)

After reading it, I'm now aware that we can't do what we will
attempt to.

We want to know if the cookie is non-persistant or a persistant
one. So we think to look for the expires value of the cookie to
let us know if it's a non or a persistant one.

Obviously, this isn't the good method after reading the
article...

Any suggests to make the difference between the two types of
cookies ? Is there a method or something that we haven't see yet
?


One way to tell the difference would be to set a value in the cookie:

// Persistent cookie.
HttpCookie cookie = new HttpCookie("MyCookie");
cookie.Expires = DateTime.AddDays(10);
cookie.Values["Persistent"] = "true";
cookie.Values["Data"] = "Hello, world!";
HttpContext.Current.Response.Cookies.Add(cookie);

or

// Non-persistent cookie because no expiraton date is set.
// Will be destroyed when the user closes their browser.
HttpCookie cookie = new HttpCookie("MyCookie");
cookie.Values["Persistent"] = "false";
cookie.Values["Data"] = "foo";
HttpContext.Current.Response.Cookies.Add(cookie);

You can use code like this to see if the cookie is persistent or not:

HttpCookieCollection cookies = HttpContext.Current.Request.Cookies;
bool isMyCookiePersistent = false;

if (cookies["MyCookie"] != null)
{
isMyCookiePersistent =
(cookies["MyCookie"].Values["Persistent"] == "true");
}
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 17 '05 #2
"Chris R. Timmons" <crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote in message news:<Xn**********************************@207.46. 248.16>...
One way to tell the difference would be to set a value in the cookie:


// Persistent cookie.
HttpCookie cookie = new HttpCookie("MyCookie");
cookie.Expires = DateTime.AddDays(10);
cookie.Values["Persistent"] = "true";
cookie.Values["Data"] = "Hello, world!";
HttpContext.Current.Response.Cookies.Add(cookie);

or

// Non-persistent cookie because no expiraton date is set.
// Will be destroyed when the user closes their browser.
HttpCookie cookie = new HttpCookie("MyCookie");
cookie.Values["Persistent"] = "false";
cookie.Values["Data"] = "foo";
HttpContext.Current.Response.Cookies.Add(cookie);

You can use code like this to see if the cookie is persistent or not:

HttpCookieCollection cookies = HttpContext.Current.Request.Cookies;
bool isMyCookiePersistent = false;

if (cookies["MyCookie"] != null)
{
isMyCookiePersistent =
(cookies["MyCookie"].Values["Persistent"] == "true");
}
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/

Thanks again ! It was this solution that we've been thinking last
week, but since a module administrate the cookie, we will have to
modify a hell lot of code. Since we have to give our project within
days, we won't have the time to do all these modifications. For sure,
for next projects, we'll change our module.

Thank you anyway :)
Fred
Nov 17 '05 #3

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

Similar topics

2
4493
by: Christophe Lance | last post by:
Hello, I use PHP session cookie to store an id number. I know how to set a cookie expiration date using the setcookie function, but how to set an expiration date when the cookie is created by...
2
7770
by: gardnern | last post by:
Is it possible to get the expiration date/time of a cookie? I need to limit someone to visiting a couple of pages for 45 minutes max and would like to show them how much time they have left. I dont...
0
1538
by: Rock | last post by:
Hi,all: I have find a example to set expiration date of word permission object, but it was using VBA code. Dim objUserPerm As Office.UserPermission Set objUserPerm =...
0
987
by: Diffident | last post by:
Hello All, I cached a string object into Cache and set absolute expiration date. Now, I would like to retrieve the absolute expiration date of that object. Any API's available? Any pointers?...
10
6796
by: Mike9900 | last post by:
Hello, I would like to store application expiration date in a file and store that file in a secure place, so the application can access the file for all the users on that computer. ...
1
1390
by: phillip.s.powell | last post by:
I have a table, "article" that has a datetime field "article_expires". In my SQL statement I have this: SELECT id, title, body FROM article WHERE (article_expires IS NOT NULL OR...
3
3424
by: dave | last post by:
I need to compute an expiration date based on the number of hours, days, or months purchased. The expiration date needs to be expressed in minutes something like '1260481600'. How can I get the...
2
1306
by: Steve Covert | last post by:
Does anybody have any clever technique to implement an expiration date in a WinForms app, such that it could outsmart any user who tries to change the system clock to avoid expiration?
2
3526
by: =?Utf-8?B?TWFyaw==?= | last post by:
Hello, I'm using Visual Studio 2008 Express Edition. My application is using the 'Sign the ClickOnce manifests' and I have created a test certificate. However, the certificate expires in one...
0
7041
marktang
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,...
0
6908
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
7084
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6739
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
5337
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4779
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.