IIS ASP - How to clear cookies in ASP?

This is Interesting: Free IT Magazines  
Home > Archive > IIS ASP > January 2008 > How to clear cookies in ASP?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author How to clear cookies in ASP?
tanya.wang@gmail.com

2008-01-02, 1:24 pm

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.

Jon Paal [MSMD]

2008-01-02, 1:24 pm

in general, the first simply changes the value of the cookie, the second destroys the cookie.

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 the cookie or checking for the existence of a cookie.



tanya.wang@gmail.com

2008-01-04, 7:20 pm

On Jan 2, 10:38=A0am, "Jon Paal [MSMD]" <Jon nospam Paal @ everywhere
dot com> wrote:
> in general, the first simply changes the value of thecookie, the second de=

stroys thecookie.
>
> the problem may be touching upon many subjects. Whether or not the login c=

heck is working properly depends upon how you are testing
> for login existence.
>
> =A0Are you looking for an empty value in thecookieor checking for the exis=

tence 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=3D12345), I got the
cookie values as follows (which is correct) -

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

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

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

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

3. After that, I use another user account (id=3D67890) 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=3D"& Request.Cookies("login_status")
Response.Write("login_id=3D"& Request.Cookies("login_id")

I got
login_status=3DOK
login_id=3D

which is wrong, I should be able to get "login_id=3D67890" 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?

Jon Paal [MSMD]

2008-01-04, 7:20 pm

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.


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com