Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove cookies under 1 domain in CookieContainer

Tags:

c#

In System.Net.CookieContainer

if I want to remove all cookies under a domain name, how?

like image 297
Eric Yin Avatar asked May 04 '12 06:05

Eric Yin


1 Answers

You could do something like this.

CookieContainer c = new CookieContainer();
var cookies = c.GetCookies(new Uri("http://www.google.com"));
foreach (Cookie co in cookies)
{
  co.Expires = DateTime.Now.Subtract(TimeSpan.FromDays(1));
}

This will expire all cookies for the domain you specify.

like image 84
Rob Avatar answered Oct 11 '22 11:10

Rob