How to clear cookies in ASP?

Discussion in 'ASP General' started by tanya.wang@gmail.com, Jan 2, 2008.

  1. Guest

    Hi,

    I have a website that would set two cookies when a user logs in
    successfully.

    <%
    response.cookies("login_status")="OK"
    response.cookies("login_id")="12345" 'This value is from database.
    response.cookies("login_id").domain="mysitexyz.com"
    %>

    and I have a question in "removing/deleting/cleaning the cookie when
    the user logs out.

    From my understanding there are two methods -

    #1 (I am currently using)
    response.cookies("login_status")=""
    response.cookies("login_id")=""

    #2
    response.cookies("login_status").expires=now
    response.cookies("login_id").expires=now

    My questions is, what's the difference, advantage and disadvantage of
    these two methods?

    I am asking this because I have noticed that there are some problems
    in #1. In my computer (I use IE7) if I login as one user, logout, and
    then login as another user, the cookie value will get mixed up.
    Somehow the response.cookies("login_status") can display correctly but
    response.cookies("login_id") cannot. But if I clean my browser cache,
    close my IE and reopen it, both cookies work fine.

    Anyone has ideas or suggestions will be highly appreciated.
    , Jan 2, 2008
    #1
    1. Advertising

  2. Guest

    On Jan 2, 10:38 am, "Jon Paal [MSMD]" <Jon nospam Paal @ everywhere
    dot com> wrote:
    > in general, the first simply changes the value of thecookie, the second destroys thecookie.
    >
    > the problem may be touching upon many subjects. Whether or not the login check is working properly depends upon how you are testing
    > for login existence.
    >
    >  Are you looking for an empty value in thecookieor checking for the existence of acookie.


    I am not looking for an empty value or the existence of it. My problem
    happens when I login->logout->login and the cookie value cannot be
    stored correctly. I will explain my question more specifically as
    below.

    1. I tried to login my website with one account (id=12345), I got the
    cookie values as follows (which is correct) -

    response.cookies("login_status")="OK"
    response.cookies("login_id")=rs("myuserid") 'This value is from
    database...
    response.cookies("login_id").domain="mysitexyz.com" 'Note that I only
    set up domain for cookie login_id

    If I Response.Write("login_id="& Request.Cookies("login_id") ), I get
    login_id=12345
    which is correct.

    2. Then I log out. The cookie values were set to ""

    response.cookies("login_status")=""
    response.cookies("login_id")=""

    3. After that, I use another user account (id=67890) to login, but I
    found that "ONLY" the cookie login_id cannot get the correct value. If
    I want to output them like

    Response.Write("login_status="& Request.Cookies("login_status")
    Response.Write("login_id="& Request.Cookies("login_id")

    I got
    login_status=OK
    login_id=

    which is wrong, I should be able to get "login_id=67890" as my correct
    result. The login ID and PW were both correct, so it couldn't be the
    DB problem. The only one problem that I can think of is at the time
    that I logout, I didnt "clean/remove" my cookie completely.

    So anyone knows where the problem is? and how to solve it?
    , Jan 4, 2008
    #2
    1. Advertising

  3. Evertjan. Guest

    Jon Paal [MSMD] wrote on 05 jan 2008 in
    microsoft.public.inetserver.asp.general:

    > your logic seems fine but it must be something else in your code or
    > when you are testing the cookie.
    >
    > After logging in, redirect to a new page and put the test in the new
    > page . See if the problem repeats or is resolved.
    >


    Please Jon, quote! This is not email.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Jan 5, 2008
    #3
  4. Evertjan. Guest

    Jon Paal [MSMD] wrote on 05 jan 2008 in
    microsoft.public.inetserver.asp.general:

    > I suggest you find another news-reader.


    Who are you referring to?

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Jan 5, 2008
    #4
  5. "Jon Paal [MSMD]" <Jon nospam Paal @ everywhere dot com> wrote in message
    news:...
    > I suggest you find another news-reader.
    >


    What Newsreader do you use?

    --
    Anthony Jones - MVP ASP/ASP.NET
    Anthony Jones, Jan 6, 2008
    #5
  6. Anthony Jones wrote:
    > "Jon Paal [MSMD]" <Jon nospam Paal @ everywhere dot com> wrote in
    > message news:...
    >> I suggest you find another news-reader.
    >>

    >
    > What Newsreader do you use?


    X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
    Bob Barrows [MVP], Jan 6, 2008
    #6
  7. "Bob Barrows [MVP]" <> wrote in message
    news:...
    > Anthony Jones wrote:
    > > "Jon Paal [MSMD]" <Jon nospam Paal @ everywhere dot com> wrote in
    > > message news:...
    > >> I suggest you find another news-reader.
    > >>

    > >
    > > What Newsreader do you use?

    >
    > X-Newsreader: Microsoft Outlook Express 6.00.2900.3138



    D'oh! nice one Bob I didn't think to check the headers. ;)

    Jon, I use OE as well. Yet I'm still irritated that when I'm forced to
    click between messages trying to get a handle on what the comments should be
    applied to. Although not as irritated as opening one of Evertjan's messages
    that it bangs on about netiquette yet again. :p


    --
    Anthony Jones - MVP ASP/ASP.NET
    Anthony Jones, Jan 6, 2008
    #7
    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. David

    Response.Clear() doesn't clear

    David, Jan 31, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    1,001
    Mark Fitzpatrick
    Jan 31, 2008
  2. Askana
    Replies:
    1
    Views:
    5,899
    Askana
    Mar 31, 2008
  3. _Who
    Replies:
    7
    Views:
    2,637
  4. InvalidLastName

    Unrecognized element 'add' after <clear></clear>

    InvalidLastName, Feb 26, 2007, in forum: ASP .Net Web Services
    Replies:
    3
    Views:
    933
    Steven Cheng[MSFT]
    Mar 6, 2007
  5. Replies:
    3
    Views:
    183
    Matt Garrish
    Sep 11, 2006
Loading...

Share This Page