Sunday, February 21, 2010

Delete all cookies and session in asp.net

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);
}
Same way we can delete all session for following code.
Session.Abandon();
Technorati Tags: ,,,

Shout it
kick it on DotNetKicks.com
If you enjoyed this post, make sure you subscribe to the dotnetjalps RSS feed to receive new posts in a reader or via email!. You can subcribe via putting email address in below box also
Subscribe via Email

8 comments:

Post a Comment

Your feedback are very important to me. Please provide your feedback via putting comments.