Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I want to kill a cookie. 1

Status
Not open for further replies.

jgsteeldev

Programmer
Feb 5, 2004
30
0
0
US
I have an application that creates a cookie. I need to be able to destroy the cookie as well. Everything I have tried so-far only sets the cookie to expire when the session is over. Does anybody know how to destroy a cookie instrantly?

Here we go Royals! Here we go!!!!!
 
Have you tried Request.Cookies.Remove(string cookiename)?

Henry
 
yeah that worked. I tried Request.Cookies("cookieName').remove and it didn't work . I put the remove in the wrong place. Thanks!!!

Here we go Royals! Here we go!!!!!
 
Another approach, set the expires.
DateTime dtExpiry = DateTime.Now.AddDays(0);
Response.Cookies[cookiename].Expires = dtExpiry;
Marty
 
cappmgr,

I tried that method. It doesn't remove the cookie till the session expires.

Here we go Royals! Here we go!!!!!
 
I like Henryas solution.
I did not explain myself very well. To remove a cookie with the Expiries you have to create a cookie with the same name and give it an Expires time that is in the past.
Marty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top