Monday, July 4, 2016

Remove cookies from CookieContainer class

The CookieContainer class does not contain a method that clears or removes the cookies associated with it. To remove them, you have to set each cookie's Expired property to True as shown below.
C#
1
2
3
4
var cookies = cookieContainer.GetCookies(new Uri("http://your_url_example_here"));
foreach (Cookie co in cookies) {
    co.Expired = true;
}

VB.NET
1
2
3
4
Dim cookies = cookieContainer.GetCookies(New Uri("http://your_url_example_here"))
For Each co As Cookie In cookies        
    co.Expired = True
Next

0 comments:

Post a Comment