Hi,
I'm having a strange problem with setting a cookie's expiration date. The
relevant code is as follows:
HttpCookie hc = new HttpCookie("MyC ookie");
hc.Values.Add(" UserName", tbUserName.Text );
hc.Expires = DateTime.Now.Ad dDays(30);
Response.Append Cookie(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.MinVal ue (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.MinVal ue 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_Session Id); 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.ToStri ng(), which seems to refer to my
cookie to me.
Does anyone have any ideas?
Thanks very much,
Jim Kelly 3 12889
"Jim Kelly" <cr*******@yaho o.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("MyC ookie"); hc.Values.Add(" UserName", tbUserName.Text ); hc.Expires = DateTime.Now.Ad dDays(30); Response.Append Cookie(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.MinVal ue (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.MinVal ue 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_Session Id); 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.ToStri ng(), 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_NO SPAM_Xcrtimmons inc.com> wrote in message
news:Xn******** *************** ***********@207 .46.248.16... "Jim Kelly" <cr*******@yaho o.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("MyC ookie"); hc.Values.Add(" UserName", tbUserName.Text ); hc.Expires = DateTime.Now.Ad dDays(30); Response.Append Cookie(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.MinVal ue (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.MinVal ue 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_Session Id); 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.ToStri ng(), 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("BEC art");
BECartCookie.Va lue = CartID.ToString ();
BECartCookie.Pa th = "/";
BECartCookie.Ex pires = dNow.AddHours(4 8);
Response.Cookie s.Set(BECartCoo kie);
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*******@yaho o.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_NO SPAM_Xcrtimmons inc.com> wrote in message news:Xn******* *************** ************@20 7.46.248.16... "Jim Kelly" <cr*******@yaho o.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("MyC ookie"); > hc.Values.Add(" UserName", tbUserName.Text ); > hc.Expires = DateTime.Now.Ad dDays(30); > Response.Append Cookie(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.MinVal ue (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.MinVal ue 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_Session Id); 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.ToStri ng(), 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? That is, what says "hang on,
the time limit has passed, so that's no longer valid"? It can't be the
browser, since that might be subverted or buggy. So does a browser send an
expired cookie value anyway and trust the website to spot it has...
|
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 :-
<authentication mode="Forms">
<forms loginUrl="CustLogin.aspx" protection="All" name="Customer" path="/"
timeout="60" />
|
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...
On my asp.net application, suddenly the forms authentication cookies
for clients have quit expiring. This results in users being able to
access the site from day to day without having to log in, even if
their
browers are closed and reopened...
|
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 expired the forms authentication cookie is assigned a new value. I am never redirected to the login page after my initial login. If I access the site from http://localhost/myapp instead of myapp.domain.com the cookies expire correctly. The cookie...
| |
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 session variables in
regular ASP) that we use to run reports from a SQL database and display them
in a web browser.
In doing some testing, I noticed that the cookies would remain there for
previous used (if I signed into our app as user 1 and...
|
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 results.
Any pointers/suggestions would be very appreciated.
Things were running as usual till until recently.
Here are the relevant pieces of code
==========================================
|
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 code :
If Not IsPostBack Then
If Request.Browser.Cookies Then
If Not IsNothing(Request.Cookies("PS")) Then
|
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.
function setCookie(name, value, expires, path, domain, secure)
{
document.cookie= name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? ";...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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,...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
| |
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
| |