When using the System.Windows.Forms.WebBrowser
control, is there a way to control which version of IE rendering engine it will use?
Asked
Active
Viewed 1,968 times
1

7wp
- 12,505
- 20
- 77
- 103
-
possible duplicate of [MSIEs WebBrowser control hosted in winforms app runs in compatibility mode](http://stackoverflow.com/questions/3554314/msies-webbrowser-control-hosted-in-winforms-app-runs-in-compatibility-mode) – Sheng Jiang 蒋晟 Sep 11 '11 at 00:08
-
possible duplicate of [Regarding IE9 WebBrowser control](http://stackoverflow.com/questions/4612255/regarding-ie9-webbrowser-control) – GuyWithDogs Sep 22 '11 at 19:41
-
Thanks for the duplicate link guys – 7wp Oct 03 '11 at 15:56
1 Answers
2
I believe IE does this by manipulating the request User-Agent
string.
compatible; MSIE 7.0;
compatible; MSIE 8.0;
compatible; MSIE 9.0;
So to use different rendering engines with WebBrowser you would need to do something similar. Unfortunately getting access to the User-Agent
in WebBrowser is not easy. You can do it if you extend the actual Com component, rather than using the .Net control.
public class ExtendedWebBrowser : WebBrowser
{
...
void BeforeNavigate(object pDisp, ref object url, ref object flags,
ref object targetFrameName, ref object postData,
ref object headers, ref bool cancel)
{
if (!headers.Contains("X-RequestFlag")
{
headers += "X-RequestFlag: true\r\n";
// append user-agent header here
headers["User-Agent"] = ...;
// cancel current request
cancel = true;
// re-request with amended details
Navigate((string)url, (string)targetFrameName, (byte[])postData,
(string)headers);
}
else
{
base.BeforeNavigate(...);
}
}
}

Community
- 1
- 1

TheCodeKing
- 19,064
- 3
- 47
- 70
-
Most solutions I've seen involve editing the registry, or they require that you have access to the web page's source code. This requires neither - great solution imho. – Jimmie Tyrrell Dec 03 '14 at 01:31