Wpf WebBrowser control and silverlight IE security issue

Its long since I worked with WPF and silverlight :(. But for the last one week I have been playing around with both of them. The case scenario that I was trying to implement was a simple intercommunication between wpf and silverlight. The requirement was very simple, as I need to build a WPF user control that wraps a simple silverlight control which is hosted in WebBrowser control with a two way communication between the WPF client and the silverlight implementation via javascript.

I will briefly describe the implementation details so as to know how I got to the problem.

First, I created a silverlight application which was supposed to  have a edit box and a button. On the html page hosting the silverlight, I added javascript  functions that were supposed to set and get the text value of the textbox on the silverlight. Also I added a handler that will be handle  silverlight button click event

And just for testing my javascript, I added some two buttons on the html file and which worked which worked great.

Then, I created a WPF user control, which utilized WebBrowser control to host the silverlight xap file. And just to do it the hard way, I dynamically wrote the html for the WebBrowser control including the javascript functions and the silverlight button handler just like I did on the html page.

And to consume my user control, I created a simple WPF client, which had three controls on its main page and handler to be used when the silverlight button is clicked.

-My custom control

-Button to set the edit box on silverlight

-Button to get the value of the silverlight edit box.

And upto here everything worked fine. For more details on how to set up all this go to here

Having done all this, I expected that my when I run my WPF client, I will see my silverlight control, but oops, I got this screen 😦


This is a security alert informing that the content contain some ActiveX components. WebBrowser  will display a warning everytime you load the component. This took me to a thorough research on the web and found various articles pointing out that the solution was to add the mark of the web. Unfortunately, this did not work out  for me.

After researching and consulting, I ended up to this function  “CoInternetSetFeatureEnabled” which you can find more details here. And here was my quick implementation which I added to the user control which is basically some simple pinvoke. By looking at the function, you will note that it takes three parameters,

Feature entry: This is a value from  InternetFeatureList enumeration showing which feature to enable or disable. And so I added this enumeration:


dwFlags: This specifies at what level do you want to put the feature control value. To my case I wanted it on the current process And so I declared the following constants

internal const uint SET_FEATURE_ON_THREAD = 0x00000001;
internal const uint SET_FEATURE_ON_PROCESS = 0x00000002;
internal const uint SET_FEATURE_IN_REGISTRY = 0x00000004;
internal const uint SET_FEATURE_ON_THREAD_LOCALMACHINE = 0x00000008;
internal const uint SET_FEATURE_ON_THREAD_INTRANET = 0x00000010;
internal const uint SET_FEATURE_ON_THREAD_TRUSTED = 0x00000020;
internal const uint SET_FEATURE_ON_THREAD_INTERNET = 0x00000040;
internal const uint SET_FEATURE_ON_THREAD_RESTRICTED = 0x00000080;

fEnable: And this is simply to indicate the feature should be enable or not. And so I did not want enable, since I wanted it for the current process, and the value was false.

With that in place I declared the function as below,

[return: MarshalAs(UnmanagedType.Error)]
internal static extern int CoInternetSetFeatureEnabled(uint FeatureEntry, [MarshalAs(UnmanagedType.U4)] uint dwFlags, bool fEnable);

In my ctor I called the function as below, passing the three arguements as per my scenario.


Hope this helps someone who might have the same case!

The best way to know you were here is to leave a comment, suggestions for topics you would like covered or even corrections.

Happy coding and see you here for another great post!

Oh Wait,please take a second to like our facebook page here. Thanks!!   🙂


Tags: , , , ,

About Piusn

Enthusiastic Software Developer

5 responses to “Wpf WebBrowser control and silverlight IE security issue”

  1. allan says :

    Genius, this really helped me out after spending a lot of time following links that took to me to the mark of the web fix which does work.

  2. BloodySall says :

    It is working! I tried to add the name of my application (i have WPF .exe programm, not Silverlight) into Windows registry (HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_LOCALMACHINE_LOCKDOWN\MyApplicationName.exe – Dword type, value 0) – it does not work. Thanks Piusn.

  3. Ivan Posadas says :

    Hey you are a crack!!! Thank you so much, it works like a charm. I spent a lot of time looking for a solution. Thanks.

  4. Raj Korpally says :

    Excellent Solution! Works like magic for me, I have used the solution for disabling FEATURE_RESTRICT_FILEDOWNLOAD for my application. Was going crazy not knowing how to fix it. Thanks.

What's your thought on the subject?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: