【问题标题】:System.Windows.Forms.WebBrowser Script Access IssueSystem.Windows.Forms.WebBrowser 脚本访问问题
【发布时间】:2026-02-12 10:55:01
【问题描述】:

我目前使用 System.Windows.Forms.WebBrowser 构建的一些门户存在问题,它们无法像在 IE 中那样正确加载内容。

我已使用 FEATURE_BROWSER_EMULATION 将仿真设置为使用 IE11,但我不明白为什么它不像已安装的 IE11。

它显示“您的浏览器中拒绝脚本访问”或根本不加载内容,说我需要升级我的浏览器。

【问题讨论】:

    标签: c# winforms internet-explorer browser


    【解决方案1】:

    也许您的代码有问题。检查Internet Feature Controls (B..C)

    值 11001 - 强制网页以 IE11 边缘模式显示,无论 !DOCTYPE 指令如何。您需要在目标系统上安装 IE11。

    private static void WebBrowserVersionEmulation()
    {
        const string BROWSER_EMULATION_KEY = 
        @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION";
        //
        // app.exe and app.vshost.exe
        String appname = Process.GetCurrentProcess().ProcessName + ".exe";
        //
        // Internet Explorer 11. Webpages are displayed in IE11 edge mode, regardless of the !DOCTYPE directive.
        const int browserEmulationMode = 11001;
    
        RegistryKey browserEmulationKey =
            Registry.CurrentUser.OpenSubKey(BROWSER_EMULATION_KEY,RegistryKeyPermissionCheck.ReadWriteSubTree) ??
            Registry.CurrentUser.CreateSubKey(BROWSER_EMULATION_KEY);
    
        if (browserEmulationKey != null)
        {
            browserEmulationKey.SetValue(appname, browserEmulationMode, RegistryValueKind.DWord);
            browserEmulationKey.Close();
        }
    }
    

    【讨论】:

    • 仍然给出“脚本”访问错误。也许这是 Flash 的问题?