C# .net WebBrowser 不显示页面(浏览器不是最新的)

标签 c# html .net visual-studio-2012 .net-4.5

我正在尝试为 Ogame 制作一个迷你机器人。

我运行我的 WebBrowser 类,它说它是 IE9 (WebBrowser.Version)。

当我执行此操作时:

wb.Navigate(www.ogame.com.us);

它说:

"Your browser is not up to date."

但是,当我在 Internet Explorer 上启动该页面时,它会显示该站点。 是 VisualStudio '12 中使用 .NET Framework 4.5 嵌入的 WebBrowser IE9 吗?
因为我不明白。 有什么解决办法吗?


提前致谢。

最佳答案

您的应用程序需要模拟不同版本的 IE。 这是通过注册表完成的。

internal class Helper
{
    public static void SetBrowserEmulation(
        string programName, IE browserVersion)
    {
        if (string.IsNullOrEmpty(programName))
        {
            programName = AppDomain.CurrentDomain.FriendlyName;
            RegistryKey regKey = Registry.CurrentUser.OpenSubKey(
                "Software\\Microsoft\\Internet Explorer\\Main" + 
                "\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);
            if (regKey != null)
            {
                try
                {
                    regKey.SetValue(programName, browserVersion, 
                        RegistryValueKind.DWord);
                }
                catch (Exception ex)
                {
                    throw new Exception("Error writing to the registry", ex);
                }
            }
            else
            {
                try
                {
                    regKey = Registry.CurrentUser.OpenSubKey("Software" + 
                        "\\Microsoft\\Internet Explorer\\Main" + 
                        "\\FeatureControl", true);
                    regKey.CreateSubKey("FEATURE_BROWSER_EMULATION");
                    regKey.SetValue(programName, browserVersion,
                        RegistryValueKind.DWord);
                }
                catch (Exception ex)
                {
                    throw new Exception("Error accessing the registry", ex);
                }
            }
        }
    }
}

internal enum IE
{
    IE7 = 7000,
    IE8 = 8000,
    IE8StandardsMode = 8888,
    IE9 = 9000,
    IE9StandardsMode = 9999,
    IE10 = 10000,
    IE10StandardsMode = 10001
}

调用这个方法。

Helper.SetBrowserEmulation(AppDomain.CurrentDomain.FriendlyName, IE.IE10);

您需要重新启动您的程序。

关于C# .net WebBrowser 不显示页面(浏览器不是最新的),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18429602/

相关文章:

c# - 如何从 C# 中的窗体返回值?

c# - 如何连接 xaml 和 xaml.cs 文件

c# - double 格式 - 显示零位或两位小数

c# - 使用 C# 和 WebRequest 上传图像?

c# - 如何从 Entity Framework 中的多个数据库/表创建单个对象

html - 文本溢出上的样式点 : ellipsis

c# - 初始化时触发自定义 DependencyProperty 的 PropertyChangedCallback

javascript - console.log 上显示什么类型的数据?

html - 一旦我们在文本字段中单击光标,背景颜色就会发生变化

.net - 系统在哪里存储图标位置?