-1

I'm trying to make a little C# program that loads a website and clears all the cookies for that website when a button is pressed.

It could also just clear all the cookies if that's easier.

I've been using the standard visual studio web browser but if anyone knows of a better way to do this I'll happily use that. I tried everything in this thread and nothing worked. I'd prefer to do this as a website instead of a program but I'd need to show another website inside my website and be able to delete the client's cookies for the other website. Any ideas?

Community
  • 1
  • 1
Sneaky Beaver
  • 705
  • 2
  • 8
  • 15

1 Answers1

0

A simple google search returned MSDN page which explains how to delete a cookie.

  1. Determine whether the cookie exists, and if so, create a new cookie with the same name.

  2. Set the cookie's expiration date to a time in the past.

  3. Add the cookie to the Cookies collection object.

The following code example shows how to set a past expiration date on a cookie.

if (Request.Cookies["UserSettings"] != null)
{
   HttpCookie myCookie = new HttpCookie("UserSettings");
   myCookie.Expires = DateTime.Now.AddDays(-1d);
   Response.Cookies.Add(myCookie);
}

Of course you'll use this in your Button.Click Event

Reference

Izzy
  • 6,740
  • 7
  • 40
  • 84