You created a cookie on you forms application now you would like to delete it. This quick article show how to do the trick...
@ 10-03-2010
by Tugberk Ugurlu

I am sure that you leave cookies into client computer on purpose or without knowing if you're an developer. Also if you create a sales website, there must be steps on this sales applicatiion and you should get the data from a previous page to another pages. The best way is always cookie if the information is not so sensetive. 

But what if we wanna delete them ? It is not as simple as creating them (essentially it is but not by directly deleting it) We cannot directly delete a file from user's computer. So what will we do? 

I assume there are another ways but the one way is setting the expiry date on a previous date. Here is the example;


if (Request.Cookies["UserSettings"] != null) {

    HttpCookie myCookie = new HttpCookie("UserSettings");
    //Here, we are setting the time to a previous time.
    //When the browser detect it next time, it will be deleted automatically.
    myCookie.Expires = DateTime.Now.AddDays(-1d);



Hope this helps :)

Hi 🙋🏻‍♂️ I'm Tugberk Ugurlu.
Coder 👨🏻‍💻, Speaker 🗣, Author 📚, Microsoft MVP 🕸, Blogger 💻, Software Engineering at Deliveroo 🍕🍜🌯, F1 fan 🏎🚀, Loves travelling 🛫🛬
Lives in Cambridge, UK 🏡