Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete Cookies from windows.form?

Tags:

I am working with the Webbrowser control on a windows.form application written in C#. I would like to write a method for deleting the cookies from the Webbrowers control after it visits a certain site. Unfortunately, I don't know how to do that exactly and haven't found a lot of help on the internet.

If anyone has experience actually doing this, not just hypothetical because it might be trickier than it seems, I don't know.

int count = webBrowser2.Document.Cookie.Length; webBrowser2.Document.Cookie.Remove(0,count); 

I would just assume something like the above code would work but I guess it won't. Can anyone shed some light on this whole cookie thing?

like image 272
Proximo Avatar asked May 26 '09 21:05

Proximo


People also ask

How do I clear my Cookies on Windows?

Click the menu button ☰, then select Settings. Select Privacy & Security, scroll to Cookies and Site Data, and then click Clear Data. Check both Cookies and Site Data and Cached Web Content, and then click Clear. A confirmation box will appear.

How do I delete all Cookies in Microsoft?

Delete all cookiesSelect Settings > Privacy, search, and services. Select Choose what to clear under Clear browsing data > Clear browsing data now. Under Time range, choose a time range from the list. Select Cookies and other site data, and then select Clear now.

Where do I find my Cookies in Windows 10?

Open Microsoft Edge and then select Settings and more > Settings > Site permissions. Select Cookies and site data. Here you can set specific controls for cookies. Select See all cookies and site data.


1 Answers

If you have JavaScript enabled you can just use this code snippet to clear to clear the cookies for the site the webbrowser is currently on.

webBrowser.Navigate("javascript:void((function(){var a,b,c,e,f;f=0;a=document.cookie.split('; ');for(e=0;e<a.length&&a[e];e++){f++;for(b='.'+location.host;b;b=b.replace(/^(?:%5C.|[^%5C.]+)/,'')){for(c=location.pathname;c;c=c.replace(/.$/,'')){document.cookie=(a[e]+'; domain='+b+'; path='+c+'; expires='+new Date((new Date()).getTime()-1e11).toGMTString());}}}})())") 

It's derived from this bookmarklet for clearing cookies.

like image 66
Jordan Milne Avatar answered Oct 08 '22 19:10

Jordan Milne