views:

466

answers:

3

How can i set the Windows Forms webbrowser control to block or allow cookies for the site it will navigate?

A: 

The question is similar to this SO question

Adeel
+1  A: 

The webbrowser control IS internet explorer. If you want to do this you may have to open an instance of the browser and block cookies through internet options. The webbrowser control itself doesn't provide a nice handy way to do that. Also doing this will block cookies from any site and not for a particular site

cyrix86
i'm sorry, i'm newbie with webbrowser control. so you're saying that i have to change the cookie settings in ie to fit my requirements?
Jepe d Hepe
Yes that's what I'm saying. For example, I had an issue where I was navigating to a page with the webbrowser within my corporate network that caused a login dialogue to appear. I didn't want this dialogue to appear so I once I set the "automatic logon with current user name and password" in Tools > Internet options, The webbrowser control no longer showed the dialogue. The wb control uses the IE engine - it IS IE. You may be able to do what you want by programmatically changing IE options in the registry using the Microsoft.Win32 dll
cyrix86
+1  A: 

You can implement a Custom Security Manager and return URLPOLICY_DISALLOW in pPolicy for each kind of action between URLACTION_NETWORK_MIN and URLACTION_NETWORK_MAX. There are several actions for cookies. For a list of cookie related actions, check your zone security settings in IE options.

There are multiple webbrowser controls in .Net. The WPF one isn't customizable for this task. The Windows Forms one is kinda customizable however its IDocHostUIhandler implementation is stuck in internal code due to security guidelines of .Net BCL. You would be much better off if you use the raw ActiveX or its wrappers that support this kind of customization, e.g. csexwb. If you have to use the winform webbrowser control, you need to create your own webbrowser site.

Sheng Jiang 蒋晟