Code to Clear Cookies

Lakhangarg
Posted by Lakhangarg under ASP.NET category on | Views : 2458
Method to clear Users Cookie
First we'll get the Cookies's Instance and then set the expiration time of 10 days before the current date. this way the cookie will be expired.

public static void ClearCookies()
{

if (HttpContext.Current.Request.Cookies["Users"] != null)
{
HttpCookie aCookie = HttpContext.Current.Request.Cookies["Users"];
aCookie.Expires = DateTime.Now.AddDays(-10);
aCookie.Value = "";
HttpContext.Current.Response.Cookies.Add(aCookie);
}

}

Comments or Responses

Login to post response