Results 1 to 4 of 4

Thread: [RESOLVED] Response or Request Cookies?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276

    Resolved [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.

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    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.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276

    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?

  4. #4
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    Re: Response or Request Cookies?

    Quote 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
  •  



Click Here to Expand Forum to Full Width