Trouble removing cookies

Discussion in 'ASP .Net Building Controls' started by Nathan Sokalski, Feb 24, 2006.

  1. I am having trouble removing cookies that I created with my site. Here is
    the code I am using to try and remove them:


    If Not Request.Cookies("username") Is Nothing Then
    Response.Cookies.Remove("username")
    If Not Request.Cookies("password") Is Nothing Then
    Response.Cookies.Remove("password")


    Is there something I am missing here? Even after I do a Session.Abandon()
    the cookies still seem to be there. Is there another step that is necessary?
    Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
     
    Nathan Sokalski, Feb 24, 2006
    #1
    1. Advertising

  2. Nathan,

    Instead of removing the cookies (I believe that just removes them from the
    server memory and not the client) you should overwrite them on the client.

    If Not Request.Cookies("username") Is Nothing Then
    Response.Cookies("username") = ""
    End If

    Oh, and even an empty cookie may not be equal to "Nothing" because it is a
    string you may need to test for "" instead.

    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche
    "Nathan Sokalski" <> wrote in message
    news:%...
    >I am having trouble removing cookies that I created with my site. Here is
    >the code I am using to try and remove them:
    >
    >
    > If Not Request.Cookies("username") Is Nothing Then
    > Response.Cookies.Remove("username")
    > If Not Request.Cookies("password") Is Nothing Then
    > Response.Cookies.Remove("password")
    >
    >
    > Is there something I am missing here? Even after I do a Session.Abandon()
    > the cookies still seem to be there. Is there another step that is
    > necessary? Thanks.
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
     
    S. Justin Gengo [MCP], Feb 24, 2006
    #2
    1. Advertising

  3. I figured out how to remove them, which is to set the Expires property to
    somewhere in the past and the use the Response.Cookies.Add() method.
    However, what is the point in removing the cookies from the server memory if
    they get resent with every Request anyway?
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate.com> wrote in
    message news:...
    > Nathan,
    >
    > Instead of removing the cookies (I believe that just removes them from the
    > server memory and not the client) you should overwrite them on the client.
    >
    > If Not Request.Cookies("username") Is Nothing Then
    > Response.Cookies("username") = ""
    > End If
    >
    > Oh, and even an empty cookie may not be equal to "Nothing" because it is a
    > string you may need to test for "" instead.
    >
    > --
    > Sincerely,
    >
    > S. Justin Gengo, MCP
    > Web Developer / Programmer
    >
    > www.aboutfortunate.com
    >
    > "Out of chaos comes order."
    > Nietzsche
    > "Nathan Sokalski" <> wrote in message
    > news:%...
    >>I am having trouble removing cookies that I created with my site. Here is
    >>the code I am using to try and remove them:
    >>
    >>
    >> If Not Request.Cookies("username") Is Nothing Then
    >> Response.Cookies.Remove("username")
    >> If Not Request.Cookies("password") Is Nothing Then
    >> Response.Cookies.Remove("password")
    >>
    >>
    >> Is there something I am missing here? Even after I do a Session.Abandon()
    >> the cookies still seem to be there. Is there another step that is
    >> necessary? Thanks.
    >> --
    >> Nathan Sokalski
    >>
    >> http://www.nathansokalski.com/
    >>

    >
    >
     
    Nathan Sokalski, Feb 25, 2006
    #3
  4. Nathan,

    I'm not certain about that myself... It really may just be the object they
    chose to hook up cookies with. It looks like the object is ultimately
    inheriting from something similar to arraylist (if it isn't arraylist itself
    I didn't bother to check). It may not be that they intended Remove to even
    be used. It may just have come along for the ride via inheritance.

    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche
    "Nathan Sokalski" <> wrote in message
    news:...
    >I figured out how to remove them, which is to set the Expires property to
    >somewhere in the past and the use the Response.Cookies.Add() method.
    >However, what is the point in removing the cookies from the server memory
    >if they get resent with every Request anyway?
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    > "S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate.com> wrote
    > in message news:...
    >> Nathan,
    >>
    >> Instead of removing the cookies (I believe that just removes them from
    >> the server memory and not the client) you should overwrite them on the
    >> client.
    >>
    >> If Not Request.Cookies("username") Is Nothing Then
    >> Response.Cookies("username") = ""
    >> End If
    >>
    >> Oh, and even an empty cookie may not be equal to "Nothing" because it is
    >> a string you may need to test for "" instead.
    >>
    >> --
    >> Sincerely,
    >>
    >> S. Justin Gengo, MCP
    >> Web Developer / Programmer
    >>
    >> www.aboutfortunate.com
    >>
    >> "Out of chaos comes order."
    >> Nietzsche
    >> "Nathan Sokalski" <> wrote in message
    >> news:%...
    >>>I am having trouble removing cookies that I created with my site. Here is
    >>>the code I am using to try and remove them:
    >>>
    >>>
    >>> If Not Request.Cookies("username") Is Nothing Then
    >>> Response.Cookies.Remove("username")
    >>> If Not Request.Cookies("password") Is Nothing Then
    >>> Response.Cookies.Remove("password")
    >>>
    >>>
    >>> Is there something I am missing here? Even after I do a
    >>> Session.Abandon() the cookies still seem to be there. Is there another
    >>> step that is necessary? Thanks.
    >>> --
    >>> Nathan Sokalski
    >>>
    >>> http://www.nathansokalski.com/
    >>>

    >>
    >>

    >
    >
     
    S. Justin Gengo [MCP], Feb 27, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Nitulescu

    Response.Cookies vs Request.Cookies

    Alex Nitulescu, Feb 3, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    8,616
    Hans Kesting
    Feb 3, 2005
  2. Nathan Sokalski

    Trouble removing cookies

    Nathan Sokalski, Feb 24, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    3,145
    S. Justin Gengo [MCP]
    Feb 27, 2006
  3. Andy Fish
    Replies:
    3
    Views:
    6,600
    Fredrik Lindner
    Nov 6, 2003
  4. Chris  Chiasson
    Replies:
    6
    Views:
    652
    Richard Tobin
    Nov 14, 2006
  5. _Who
    Replies:
    7
    Views:
    2,767
Loading...

Share This Page