38

So I have an C# Form application that utilizes the web browser component. Apparently Response.Write(Request.Browser.Version.ToString()); returns "7.0" when I visit my test page from the web browser component.

How can I make this web browser component use IE8?

abatishchev
  • 92,232
  • 78
  • 284
  • 421
Chris
  • 1,691
  • 4
  • 18
  • 28
  • I assume that app is running from a PC with IE 8 installed, yea? – o.k.w Nov 23 '09 at 23:57
  • Yes. I've tried it on 3 computers (all are running IE8). – Chris Nov 23 '09 at 23:58
  • 1
    The answer to this http://stackoverflow.com/questions/937573/changing-the-useragent-of-the-webbrowser-control-winforms-c seems to indicate you need to extend the component in order to set the user-agent that is passed in requests it generates. – Amal Sirisena Nov 24 '09 at 00:10
  • @Amal: you should answer instead of commenting. :) – o.k.w Nov 24 '09 at 03:16
  • @Amal, does changing the user agent, change how the page is rendered? There are some bugs I have with CSS that render correctly in IE8 but not IE7. I don't think just changing the user agent would fix this. – Chris Nov 24 '09 at 17:18
  • @Chris - Sorry I wasn't sure if I had understood your question correctly which is why I added a comment rather than answer. looks like Plip came up with the answer you were looking for. – Amal Sirisena Nov 24 '09 at 19:36

4 Answers4

35

It appears you need to fiddle with the registry as per this article: -

http://blogs.msdn.com/ie/archive/2009/03/10/more-ie8-extensibility-improvements.aspx

To run a WebBrowser control in IE8 Standards Mode, use the following new value into the registry:

[(HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE)\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION] 
"MyApplication.exe" = dword 8000 (Hex: 0x1F40)

To run in IE7 Standards Mode, use the following registry value:

[(HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE)\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION] 
"MyApplication.exe" = dword 7000 (Hex: 0x1B58)

For IE8 RTM, we’ve added a new “forced” IE8 Standards Mode value. When an application opts into this mode, the Web Browser control will use the IE8 User-Agent string and Browser Emulation mode strictly. It will also ignore fallback features such as the built-in Compatibility View list and the user-generated Compatibility View list when loading pages. To run in “forced” IE8 Standards Mode, use the following registry value:

[(HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE)\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION] 
"MyApplication.exe" = dword 8888 (Hex: 0x22B8)

In all of these examples, “MyApplication.exe” refers to the name of your application.

Kiquenet
  • 13,271
  • 31
  • 133
  • 232
Plip
  • 1,020
  • 8
  • 9
  • Thanks for this. This seems like the only fix. However, I think I'll stick with an IE7 web browser for now. – Chris Nov 24 '09 at 17:19
29

The answer may come late and might not apply to your case, but according to Ron's answer on the question WPF .net4 webBrowser and Internet Explorer 8, you can also control the web browser if you have control over the served page:

<meta http-equiv="X-UA-Compatible" content="IE=edge"/>

While this apparently does not change the user agent, it seems that conditionals like

<!--[if lt IE 8]>

and CSS border-radius are being evaluated properly, indicating that the newest engine (IE 9 on my system) is actually being used despite the user agent reporting MSIE 7.0.

Community
  • 1
  • 1
Arc
  • 10,545
  • 4
  • 46
  • 70
16

I did follow this and it was not working until I realized it was because I was debugging in visual studio.

On top of setting the registry for your application:

Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION", 
  System.AppDomain.CurrentDomain.FriendlyName, value);

You should also set it for your debugging (visual studio hosted) application:

Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION",
  System.AppDomain.CurrentDomain.FriendlyName.Replace(".exe",".vshost.exe"), value);
Pascal Ganaye
  • 815
  • 9
  • 23
  • 2
    You can use System.AppDomain.CurrentDomain.FriendlyName to get the application name, rather than hard-coding it. – Fiach Reid Feb 26 '15 at 13:01
0

You should change the registry for your system while you are in debugging too.

public void ChangeRegistery()
{
        string key = @"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION";
        var value = 0x22B8;

        Microsoft.Win32.Registry.SetValue(key, System.AppDomain.CurrentDomain.FriendlyName, value,Microsoft.Win32.RegistryValueKind.DWord);
        #if DEBUG 
            Microsoft.Win32.Registry.SetValue(key, System.AppDomain.CurrentDomain.FriendlyName.Replace(".exe", ".vshost.exe"), value, Microsoft.Win32.RegistryValueKind.DWord);
        #endif
}