Showing posts with label delete all cookies. Show all posts
Showing posts with label delete all cookies. Show all posts

Saturday, 1 February 2014

Remove all cookies from browser in c# | Pravin Prajapati

Remove all cookies from browser in c#

Create Method

 protected void removeCookie()
        {
            HttpCookie aCookie;
            string cookieName;
            int limit = Request.Cookies.Count;
            for (int i = 0; i < limit; i++)
            {
                cookieName = Request.Cookies[i].Name;
                aCookie = new HttpCookie(cookieName);
                aCookie.Expires = DateTime.Now.AddDays(-1);
                aCookie.Value = string.Empty;
                Response.Cookies.Add(aCookie);
            }
        }

Call Method

 protected void Page_Load(object sender, EventArgs e)
        {
            removeCookie(); //call method here
        }