How to clear cookies in ASP?
How to clear cookies in ASP?
am 02.01.2008 19:02:41 von tanya.wang
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.
Re: How to clear cookies in ASP?
am 02.01.2008 19:38:30 von Jon Paal
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.
Re: How to clear cookies in ASP?
am 04.01.2008 21:16:53 von tanya.wang
On Jan 2, 10:38=A0am, "Jon Paal [MSMD]"
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?
Re: How to clear cookies in ASP?
am 05.01.2008 00:23:08 von Jon Paal
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.
Re: How to clear cookies in ASP?
am 05.01.2008 11:31:25 von exjxw.hannivoort
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)
Re: How to clear cookies in ASP?
am 05.01.2008 22:31:11 von Jon Paal
I suggest you find another news-reader.
Re: How to clear cookies in ASP?
am 06.01.2008 00:24:49 von exjxw.hannivoort
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)
Re: How to clear cookies in ASP?
am 06.01.2008 09:31:09 von Anthony Jones
"Jon Paal [MSMD]" wrote in message
news:13nvtp09e3vlfed@corp.supernews.com...
> I suggest you find another news-reader.
>
What Newsreader do you use?
--
Anthony Jones - MVP ASP/ASP.NET
Re: How to clear cookies in ASP?
am 06.01.2008 13:20:58 von reb01501
Anthony Jones wrote:
> "Jon Paal [MSMD]" wrote in
> message news:13nvtp09e3vlfed@corp.supernews.com...
>> 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"
Re: How to clear cookies in ASP?
am 06.01.2008 16:25:02 von Anthony Jones
"Bob Barrows [MVP]" wrote in message
news:uMxpT6FUIHA.4768@TK2MSFTNGP02.phx.gbl...
> Anthony Jones wrote:
> > "Jon Paal [MSMD]" wrote in
> > message news:13nvtp09e3vlfed@corp.supernews.com...
> >> 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