473,805 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
+ 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_pr opertyID);
cookie.Value = m_property;
if (m_temporaryCoo kie == false)
{
cookie.Expires = DateTime.MaxVal ue;
}
HttpContext.Cur rent.Response.C ookies.Add(cook ie);

And when we want to see the value :

HttpCookie cookie =
HttpContext.Cur rent.Request.Co okies[m_propertyID];

if ( cookie != null)
{
HttpContext.Cur rent.Response.W rite(cookie.Exp ires);
}
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 5095
fg*****@neomedi a.com (Frederic Gignac) wrote in
news:88******** *************** ***@posting.goo gle.com:
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("MyC ookie");
cookie.Expires = DateTime.AddDay s(10);
cookie.Values["Persistent "] = "true";
cookie.Values["Data"] = "Hello, world!";
HttpContext.Cur rent.Response.C ookies.Add(cook ie);

or

// Non-persistent cookie because no expiraton date is set.
// Will be destroyed when the user closes their browser.
HttpCookie cookie = new HttpCookie("MyC ookie");
cookie.Values["Persistent "] = "false";
cookie.Values["Data"] = "foo";
HttpContext.Cur rent.Response.C ookies.Add(cook ie);

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

HttpCookieColle ction cookies = HttpContext.Cur rent.Request.Co okies;
bool isMyCookiePersi stent = false;

if (cookies["MyCookie"] != null)
{
isMyCookiePersi stent =
(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_NO SPAM_Xcrtimmons inc.com> wrote in message news:<Xn******* *************** ************@20 7.46.248.16>...
One way to tell the difference would be to set a value in the cookie:


// Persistent cookie.
HttpCookie cookie = new HttpCookie("MyC ookie");
cookie.Expires = DateTime.AddDay s(10);
cookie.Values["Persistent "] = "true";
cookie.Values["Data"] = "Hello, world!";
HttpContext.Cur rent.Response.C ookies.Add(cook ie);

or

// Non-persistent cookie because no expiraton date is set.
// Will be destroyed when the user closes their browser.
HttpCookie cookie = new HttpCookie("MyC ookie");
cookie.Values["Persistent "] = "false";
cookie.Values["Data"] = "foo";
HttpContext.Cur rent.Response.C ookies.Add(cook ie);

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

HttpCookieColle ction cookies = HttpContext.Cur rent.Request.Co okies;
bool isMyCookiePersi stent = false;

if (cookies["MyCookie"] != null)
{
isMyCookiePersi stent =
(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
4519
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 the session_start function ? I know the cookie expires after the session ends, but when I look at my HTTP headers, the cookie's expiration date created by the session is set to 19
2
7941
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 think a javascript timer will work, because the timer should continue where it left off at on the previous page. Any suggestions?
0
1557
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 = ActiveWorkbook.Permission.Add( _ "user@domain.com", _ msoPermissionRead + msoPermissionEdit, #12/31/2005#) ------>set
0
1007
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? Thank you!!
10
6820
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. IsolatedStorage is a good technique but it is for the each user only and is not machine level. Registry is not good because the user may not have access permission. Application directory is not good because the file could be deleted and so the...
1
1406
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 article_expires = '' OR article_expires LIKE '0000-00-00%' OR article_expires < now()) ORDER BY ranking DESC, record_entered DESC, upper(title) ASC, upper(body) ASC
3
3444
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 current date and time expressed in minutes? Once I have this number I can add the number of minutes purchased to the current date/time to get the expiration date.
2
1322
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
3552
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 year. Is there a way to extend the expiration date? I thought perhaps the SDK would have some tools in it for this, but the SDK will not install on my Express Edition. I expect that my application will be used for a few years, and don't know...
0
10609
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10366
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10105
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9185
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7646
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5542
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4323
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 we have to send another system
2
3845
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.