0

Hi, I've tried several combinations of commands like the following to finish a session:

Request.Cookies.Remove("cookie1");
Request.Cookies.Remove("cookie2");
Request.Cookies.Clear();
        
Response.Cookies.Remove("cookie1");
Response.Cookies.Remove("cooke2");
Response.Cookies.Clear();

But after that I go to another page that checks for the existence of the cookies, and it still finds them.

Any ideas?

Thanks in advance.

3
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by sandybarasker
0

Are you sure the page isn't cached? If the page is cached, then it isn't finding the cookies, just using the settings on when they found them in the past.

0

It was cached actually, but I've added the

Response.AddHeader("cache-control", "no-cache");

line to avoid caching and it was still the same.

Finally I set the expiration date of the cookie to -1 and it's working now.

Thanks.

0
if (Request.Cookies["UserSettings"] != null)
 {
HttpCookie myCookie = new HttpCookie("UserSettings");
myCookie.Expires = DateTime.Now.AddDays(-1d);
Response.Cookies.Add(myCookie);
 }

this code is working fine for delete cookies

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.