C# 指定WebBrowser 的 User Agent 版本

今天用WebBrowser 打开网页,本机ie是ie9 可是WebBrowser 显示的效果明显不是ie9 ,百度查资料才知道,其实是因为直接用IE跟使用WebBrowser 运行的是不同的User Agent。

所以只需把 WebBrowser的User Agent修改下,方法是打开注册表修改IE的Feature

32 bit:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION
64 bit:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION

手动设置

C# 指定WebBrowser 的 User Agent 版本

C# 指定WebBrowser 的 User Agent 版本

 

 

//代码设置

public Form1()
{
  var appName = Process.GetCurrentProcess().MainModule.ModuleName;
  Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION", appName, 9999, RegistryValueKind.DWord);
  InitializeComponent();

}

 

参考资料 Internet Feature Controls (B..C)