Cookies are one of most important features of web application. From where we store little information on client side in one of my project we need to delete all cookies and as you can not delete cookies from server side so we have to expire them manually. Here is the code for that.
string[] myCookies = Request.Cookies.AllKeys;
foreach (string cookie in myCookies)
{
Response.Cookies[cookie].Expires = DateTime.Now.AddDays(-1);
}
Session.Abandon();
I wish it were that simple. My cookies have this annoying tendency to reappear no matter how hard I try to delete them.
ReplyDeleteBob what is the problem you are facing with deleting cookie
ReplyDeletesame code i use it..but it work in local host only not in actual live site
ReplyDeleteKartheeswaran - What's the problem you are having to delete cookie that may be you have not used your cookie domain property.
ReplyDeleteIn my site i use google language translate combo box to change languages,
ReplyDeletei set the cookie value "/en/en" in google translate bar.
when the user or admin login in my site ,i hide the translate bar and delete cookie...
it work properly in local host,when launch the website in Server.the code not work ,still cookies are in browser....
Kartheeswaran - I think you have problem with cookie domain property- see following linke.
ReplyDeletehttp://stackoverflow.com/questions/513782/why-did-asp-net-generate-the-same-cookie-key-for-a-domain-and-subdomain . If you can send me the code then it would be very help full!!
Good Explanation
ReplyDelete@9f867cef981943a0c40aa457409b74be:disqus - Nice work!!
ReplyDelete