1

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

错误弹出:

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;
    }
4

1 回答 1

0

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

参考:https://social.msdn.microsoft.com/Forums/vstudio/en-US/4f686de1-8884-4a8d-8ec5-ae4eff8ce6db/new-wpf-webbrowser-how-do-i-suppress-script-errors?论坛=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 });

}
于 2016-02-12T13:04:09.860 回答