I have the following C# code which logs the user’s url in a cookie. If the cookie already exists, it appends the new value to the existing value separated by a pipe character. My ASPX page looks up this cookie, chops up the values based on the pipe character and binds them to a grid. So far so good. But when I go to Internet Options in my browser and clear my cookies, temp files etc and refresh the page, the page can still read the values from the cookie. It appears that the cookie did not deleted after all. It is being persisted no matter how. What gives? If the user clears the cookies from their browser, the grid control in my ASPX should be empty. The page is not using caching or anything.
HttpCookie recentlyViewedCookie = Request.Cookies["RecentlyViewedCookie"];
if (recentlyViewedCookie != null)
{
string value = recentlyViewedCookie.Value;
value = string.Format("{0}|{1}*{2}", value, DateTime.Now.ToString("MM/dd/yyyy"), Request.Url.ToString());
recentlyViewedCookie.Value = value;
Response.Cookies.Add(recentlyViewedCookie);
}
else
{
recentlyViewedCookie = new HttpCookie("RecentlyViewedCookie");
recentlyViewedCookie.Value = string.Format("{0}*{1}", DateTime.Now.ToString("MM/dd/yyyy"), Request.Url.ToString());
recentlyViewedCookie.Expires = DateTime.Now.AddMonths(1);
Response.Cookies.Add(recentlyViewedCookie);
}
Thanks for any answers.
First of all is NOT a good practice to ask from your user to clear all the cookies, for your page to run correct.
Second, you did not say what browser you use, because this is a browser part, and when you clear the cookies you need to close also the browser, or at least do not have open your page (because you say “refresh the page”). If you have clear the cookies, but you have open the page on the browser, the browser have been keep the cookie for that page – is part of the render that have done, is part of the javascript global values for that page, so the cookie exist until you close AND the page of you. The clear all cookies is not clear the active memory, just delete all the cookies files from the cache.
at the end I suggest to think a different method for your page flow actions, and NOT ask from your user to clear all the cookies.