无法在Webbrowser控件中禁用“安全警告”窗口

时间:2012-10-23 11:02:54

标签: c# wpf

我尝试禁用安全弹出窗口,但它仍然提示。

错误弹出:

Do you want to view only the webpage content that was delivered securely This webpage contains content that will not be delivered using a secure HTTPS connection, which could compromise the security of the entire webpage.”“This page contains both secure and nonsecure items. Do you want to display the nonsecure items?”

WPF:

<WebBrowser Name="wbGateway" Width="700" Height="600" 
                        OverridesDefaultStyle="False"
                        ScrollViewer.CanContentScroll="False"
                        ScrollViewer.HorizontalScrollBarVisibility="Hidden" 
                        ScrollViewer.VerticalScrollBarVisibility="Hidden"></WebBrowser>

代码:

private void wbGateway_Navigating(object sender, NavigatingCancelEventArgs e)
        {
ServicePointManager.ServerCertificateValidationCallback = new 


RemoteCertificateValidationCallback(ValidateServerCertificate);
}

    public static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
    {
        return true;
    }

1 个答案:

答案 0 :(得分:0)

在这里,我们使用解决方案:我在Browser_Navigated事件上运行它,因为在此之前底层的activeX组件为null。

<强>价: https://social.msdn.microsoft.com/Forums/vstudio/en-US/4f686de1-8884-4a8d-8ec5-ae4eff8ce6db/new-wpf-webbrowser-how-do-i-suppress-script-errors?forum=wpf

    private void Browser_Navigating_1(object sender, NavigatingCancelEventArgs e)
    {
    HideScriptErrors(Browser,true);

    }

public void HideScriptErrors(WebBrowser wb, bool Hide)
{

    FieldInfo fiComWebBrowser = typeof(WebBrowser).GetField("_axIWebBrowser2", BindingFlags.Instance | BindingFlags.NonPublic);
    if (fiComWebBrowser == null) return;
    object objComWebBrowser = fiComWebBrowser.GetValue(wb);

    if (objComWebBrowser == null) return;

    objComWebBrowser.GetType().InvokeMember(
    "Silent", BindingFlags.SetProperty, null, objComWebBrowser, new object[] { Hide });

}