|
-
Mar 25th, 2005, 04:58 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] Response or Request Cookies?
What's the difference in Response.Cookies and Request.Cookies?
I can write to Response.Cookies and I get the cookie but after it expires it's still there.
I tried Request.Cookies.Add and the cookie never shows up.
Last edited by wey97; Apr 22nd, 2005 at 08:47 AM.
-
Mar 28th, 2005, 08:08 AM
#2
I wonder how many charact
Re: Response or Request Cookies?
The cookie collection of the Request is what cookies the client had at the time it connected to the server to request a page.
The cookie collection of the Response is what cookies the server will send to the client. This is where you add cookies.
The browser itself is fully responsible for clearing cookies - some browsers behave differently, however a consistent way to clear a cookie is to specifically set that it was to expire 3 years ago (even if you just issued it during this browser session) - most browsers will then immediately kill that cookie.
-
Mar 30th, 2005, 09:44 AM
#3
Thread Starter
Frenzied Member
Re: Response or Request Cookies?
I'm writing a cookie:
Code:
HttpCookie h = new HttpCookie("mycookie", "cookie value");
h.Expires = new DateTime(2005, 3, 30, 16, 55, 0);
Response.Cookies.Add(h);
Why won't Response.Cookies.Remove("mycookie"); work?
I know you have to set it to expire on a past date:
Code:
HttpCookie h = Request.Cookies.Get("mycookie");
h.Expires = new DateTime(2002, 3, 30, 16, 55, 0);
Response.Cookies.Set(h);
but why have Remove() if it won't work?
-
Mar 31st, 2005, 07:51 AM
#4
I wonder how many charact
Re: Response or Request Cookies?
 Originally Posted by wey97
I'm writing a cookie:
Code:
HttpCookie h = new HttpCookie("mycookie", "cookie value");
h.Expires = new DateTime(2005, 3, 30, 16, 55, 0);
Response.Cookies.Add(h);
Why won't Response.Cookies.Remove("mycookie"); work?
I know you have to set it to expire on a past date:
Code:
HttpCookie h = Request.Cookies.Get("mycookie");
h.Expires = new DateTime(2002, 3, 30, 16, 55, 0);
Response.Cookies.Set(h);
but why have Remove() if it won't work?
Remove only works if you set the cookie in the same response session. So if function A adds the cookie to the Response object, and then three functions later, some code logic decides it needs to be removed, then Remove() works.
It doesn't however remove a cookie added during a previous response. I hear you though, it took me a while to figure that out, and the docs don't clarify that at all.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|