473,382 Members | 1,336 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Can't remove cookies!

Hi,

I have a login page where if the user wants his access codes to be saved are
set into a cookie. In the logout page, I want to delete those cookies. I
tried this and this is not working at all:

if (Request.Cookies[COOKIE_USER] != null
&& Request.Cookies[admin.COOKIE_PSWD] != null)
{
Response.Cookies[COOKIE_USER].Value = null;
Response.Cookies[COOKIE_PSWD].Value = null;
Response.Cookies.Remove(COOKIE_USER);
Response.Cookies.Remove(COOKIE_PSWD);
}

If I do a response.write like this right after or on another page, it shows
that the cookies are still set:

Response.Write((Request.Cookies[COOKIE_USER] == null) + " " +
Request.Cookies[COOKIE_USER].Value + " ");
Response.Write((Request.Cookies[COOKIE_PSWD] == null) + " " +
Request.Cookies[COOKIE_PSWD].Value);

Why is this not working? How do we remove user's cookie?

Thanks

Stephane
Nov 19 '05 #1
6 8821
"=?Utf-8?B?U3RlcGhhbmU=?=" <St******@discussions.microsoft.com>
wrote in news:9E**********************************@microsof t.com:
Hi,

I have a login page where if the user wants his access codes to
be saved are set into a cookie. In the logout page, I want to
delete those cookies. I tried this and this is not working at
all:

if (Request.Cookies[COOKIE_USER] != null
&& Request.Cookies[admin.COOKIE_PSWD] != null)
{
Response.Cookies[COOKIE_USER].Value = null;
Response.Cookies[COOKIE_PSWD].Value = null;
Response.Cookies.Remove(COOKIE_USER);
Response.Cookies.Remove(COOKIE_PSWD);
}

If I do a response.write like this right after or on another
page, it shows that the cookies are still set:

Response.Write((Request.Cookies[COOKIE_USER] == null) + " " +
Request.Cookies[COOKIE_USER].Value + " ");
Response.Write((Request.Cookies[COOKIE_PSWD] == null) + " " +
Request.Cookies[COOKIE_PSWD].Value);

Why is this not working? How do we remove user's cookie?


Stephane,

Set the cookie's expiration date to sometime in the past. When it is
sent back to the browser, the browser will look at the cookie's date
and determine it has expired and delete it. For example:

Response.Cookies[COOKIE_USER].Expires = DateTime.Now.AddDays(-10);
Response.Cookies[COOKIE_PSWD].Expires = DateTime.Now.AddDays(-10);

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 19 '05 #2
Hi,

I tried this and the damned cookie is still there!

Response.Cookies[admin.COOKIE_USER].Expires = DateTime.Now.AddDays(-10);
Response.Cookies[admin.COOKIE_PSWD].Expires = DateTime.Now.AddDays(-10);
Response.Cookies[admin.COOKIE_USER].Value = null;
Response.Cookies[admin.COOKIE_PSWD].Value = null;
Response.Cookies.Remove(admin.COOKIE_USER);
Response.Cookies.Remove(admin.COOKIE_PSWD);

Maybe it's the way I set the cookie?

HttpCookie cookieUsr = new HttpCookie(COOKIE_USER, username);
cookieUsr.Expires = DateTime.Now.AddDays(1000);
HttpCookie cookiePwd = new HttpCookie(COOKIE_PSWD, encryptedValue);
cookiePwd.Expires = DateTime.Now.AddDays(1000);
Response.SetCookie(cookieUsr);
Response.SetCookie(cookiePwd);

Thanks for any help!

Stephane
"Chris R. Timmons" wrote:
"=?Utf-8?B?U3RlcGhhbmU=?=" <St******@discussions.microsoft.com>
wrote in news:9E**********************************@microsof t.com:
Hi,

I have a login page where if the user wants his access codes to
be saved are set into a cookie. In the logout page, I want to
delete those cookies. I tried this and this is not working at
all:

if (Request.Cookies[COOKIE_USER] != null
&& Request.Cookies[admin.COOKIE_PSWD] != null)
{
Response.Cookies[COOKIE_USER].Value = null;
Response.Cookies[COOKIE_PSWD].Value = null;
Response.Cookies.Remove(COOKIE_USER);
Response.Cookies.Remove(COOKIE_PSWD);
}

If I do a response.write like this right after or on another
page, it shows that the cookies are still set:

Response.Write((Request.Cookies[COOKIE_USER] == null) + " " +
Request.Cookies[COOKIE_USER].Value + " ");
Response.Write((Request.Cookies[COOKIE_PSWD] == null) + " " +
Request.Cookies[COOKIE_PSWD].Value);

Why is this not working? How do we remove user's cookie?


Stephane,

Set the cookie's expiration date to sometime in the past. When it is
sent back to the browser, the browser will look at the cookie's date
and determine it has expired and delete it. For example:

Response.Cookies[COOKIE_USER].Expires = DateTime.Now.AddDays(-10);
Response.Cookies[COOKIE_PSWD].Expires = DateTime.Now.AddDays(-10);

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/

Nov 19 '05 #3

Try this (I only know vb so I may not have all the syntax correct) Also,
you want to make sure the request.cookie exists first or it will throw an
error.
if not request.cookies[admin.COOKIE_USER] is nothing then
Request.Cookies[admin.COOKIE_USER].Expires = DateTime.Now.AddDays(-10);
Request.Cookies[admin.COOKIE_PSWD].Expires = DateTime.Now.AddDays(-10);
Reponse.Cookies.add(Request.Cookies[admin.COOKIE_USER])
Response.Cookies.add(Request.Cookies[admin.COOKIE_PSWD])

Basically you are adding an expired cookie. From my experience remove cookie
does not work I saw an explanation of why somewhere but I can't remember
where.
Nov 19 '05 #4

"vMike" <Mi****************@noYandZ.geZwaYrrenZ.com> wrote in message
news:cq**********@ngspool-d02.news.aol.com...

Try this (I only know vb so I may not have all the syntax correct) Also,
you want to make sure the request.cookie exists first or it will throw an
error.
if not request.cookies[admin.COOKIE_USER] is nothing then
Request.Cookies[admin.COOKIE_USER].Expires = DateTime.Now.AddDays(-10);
Request.Cookies[admin.COOKIE_PSWD].Expires = DateTime.Now.AddDays(-10);
Reponse.Cookies.add(Request.Cookies[admin.COOKIE_USER])
Response.Cookies.add(Request.Cookies[admin.COOKIE_PSWD])

Basically you are adding an expired cookie. From my experience remove cookie does not work I saw an explanation of why somewhere but I can't remember
where.


BTW I don't think the cookie is actually removed, it is just expired. I
don't think you can erase the cookie from the client. Others may know if
that is possible.
Nov 19 '05 #5

"Stephane" <St******@discussions.microsoft.com> wrote in message
news:CF**********************************@microsof t.com...
Hi,

I tried this and the damned cookie is still there!

Response.Cookies[admin.COOKIE_USER].Expires = DateTime.Now.AddDays(-10);
Response.Cookies[admin.COOKIE_PSWD].Expires = DateTime.Now.AddDays(-10);
Response.Cookies[admin.COOKIE_USER].Value = null;
Response.Cookies[admin.COOKIE_PSWD].Value = null;
Response.Cookies.Remove(admin.COOKIE_USER);
Response.Cookies.Remove(admin.COOKIE_PSWD);

Maybe it's the way I set the cookie?

HttpCookie cookieUsr = new HttpCookie(COOKIE_USER, username);
cookieUsr.Expires = DateTime.Now.AddDays(1000);
HttpCookie cookiePwd = new HttpCookie(COOKIE_PSWD, encryptedValue);
cookiePwd.Expires = DateTime.Now.AddDays(1000);
Response.SetCookie(cookieUsr);
Response.SetCookie(cookiePwd);

This article may help http://www.codeproject.com/aspnet/aspnetcookies.asp
Nov 19 '05 #6
I finally had it to work... I remove it from the request too.

Here's my code:

HttpCookie c1 = Request.Cookies[admin.COOKIE_USER];
HttpCookie c2 = Request.Cookies[admin.COOKIE_PSWD];
Request.Cookies.Remove(admin.COOKIE_USER);
Request.Cookies.Remove(admin.COOKIE_PSWD);
c1.Expires = DateTime.Now.AddDays(-10);
c2.Expires = DateTime.Now.AddDays(-10);
c1.Value = null;
c2.Value = null;
Response.SetCookie(c1);
Response.SetCookie(c2);

Stephane

"vMike" wrote:

"Stephane" <St******@discussions.microsoft.com> wrote in message
news:CF**********************************@microsof t.com...
Hi,

I tried this and the damned cookie is still there!

Response.Cookies[admin.COOKIE_USER].Expires = DateTime.Now.AddDays(-10);
Response.Cookies[admin.COOKIE_PSWD].Expires = DateTime.Now.AddDays(-10);
Response.Cookies[admin.COOKIE_USER].Value = null;
Response.Cookies[admin.COOKIE_PSWD].Value = null;
Response.Cookies.Remove(admin.COOKIE_USER);
Response.Cookies.Remove(admin.COOKIE_PSWD);

Maybe it's the way I set the cookie?

HttpCookie cookieUsr = new HttpCookie(COOKIE_USER, username);
cookieUsr.Expires = DateTime.Now.AddDays(1000);
HttpCookie cookiePwd = new HttpCookie(COOKIE_PSWD, encryptedValue);
cookiePwd.Expires = DateTime.Now.AddDays(1000);
Response.SetCookie(cookieUsr);
Response.SetCookie(cookiePwd);

This article may help http://www.codeproject.com/aspnet/aspnetcookies.asp

Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dan | last post by:
I persist the login info using cookies so that a user doesn't have to login every time they come to our website, unless they previously logged out. Everything works OK on W98 SE, and Windows XP Pro...
0
by: Soul | last post by:
Hi, I have a C# ASP.Net page allow users to enter their name and will set those value as cookie after click on "Submit" button. In addition, if user click on "Change" button, the cookie should...
0
by: Urban Bettag | last post by:
I want to use persistent cookies for my login page. For example, the user types in his username and password. He can check a box and the system should remember his username on a next visit. I have...
3
by: Wysiwyg | last post by:
After a server created cookie is processed on the client I want it removed, cleared, or expired in the javascript block but have been unable to do this. If I set a cookie value in the server code...
0
by: Alan Silver | last post by:
Hello, I am having a problem setting and resetting cookies. I'm sure I just doing something really stupid as this is such a basic issue, but I can find any answer. Please can someone help me? ...
1
by: terryspanky | last post by:
----------------------Below are all the codes don't have errors---- The only problem I have is when I Delete, I'ts not deleting the subject that I click. I want to use the above codes to modify the...
24
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How can I see in javascript if a web browser accepts cookies?...
4
by: Jon Slaughter | last post by:
I have developed a technique to add and remove cookies after output... wondering if there is something else like this out there? Jon
0
by: rn5a | last post by:
This is how I am creating & then reading cookies: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) 'create cookies Response.Cookies("UserName").Value = "Ron"...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.