I want websites to not able to read cookies or write new cookies in a webbrowser c# control application. I will prefer to disable all read/write cookies operation for all websites when the webbrowser c# application runs, if not then I have a list of websites whose read/write cookies operation should be disabled.
I am using .NET 2.0 framework but can also use 4.5
You can't disable cookies only on your web browser control. The control is essentially an embedded Internet Explorer and shares the user's Internet Explorer settings. If you don't mind blocking cookies on all other instances of Internet Explorer (maybe you use Chrome or Firefox for the rest of your browsing) you can do the following:
(From: http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/90834f20-c89f-42f9-92a8-f67ccee3799a/)
You could also delete all the cookies after you visit a page, but I don't think this will fulfill your goal of being completely anonymous.
I did a little digging and I think you can use InternetSetOption and the INTERNET_SUPPRESS_COOKIE_PERSIST flag. According to the documentation, this will only work for Internet Explorer 8 and later.
Then when you initialize your app try:
Hopefully this puts you on the right track. See also:
How to set and delete cookies from WebBrowser Control for arbitrary domains
How do I use InternetSetOption?
Clear Cookies Cache for Multiple WebBrowser Control with WinInet in Winform Application
You can use InternetSetOption with the option flag INTERNET_OPTION_SUPPRESS_BEHAVIOR. This option flag should be used together with INTERNET_SUPPRESS_COOKIE_PERSIST option.
The setting is valid per process, so the method can be called at any place, but before
webBrowser.Navigate()
.Note:
- Requires Internet Explorer 8.0 or later.
- To reset use
int option = 4; //INTERNET_SUPPRESS_COOKIE_PERSIST_RESET