我尝试禁用安全弹出窗口,但它仍然提示。
错误弹出:
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;
}
答案 0 :(得分:0)
在这里,我们使用解决方案:我在Browser_Navigated事件上运行它,因为在此之前底层的activeX组件为null。
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 });
}