Code to Clear Cookies

Posted by Lakhangarg under ASP.NET category on | Views : 2432
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 = "";


Comments or Responses

Login to post response