c# - 如何在 Webbrowser 控件中禁用 "Security Alert"窗口

标签 c# https browser certificate

我正在使用 Webbrowser 控件使用“不受信任的证书”登录到 HTTPS 站点。 但是我弹出了这样一个关于不受信任的证书的标准窗口“安全警报”:

Security Alert window

我必须按标题找到此窗口并发送 Alt+Y 以按 Yes:

int iHandle = NativeWin32.FindWindow(null, "Security Alert");
NativeWin32.SetForegroundWindow(iHandle);
System.Windows.Forms.SendKeys.Send("Y%");

但是用户可以看到这个窗口的闪烁。

如何忽略此警报?
或者在 Webbrowser 控件中禁用此“不受信任的证书”检查?

最佳答案

应该这样做:

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

ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);

显然,盲目地允许证书存在安全风险。小心。

关于c# - 如何在 Webbrowser 控件中禁用 "Security Alert"窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/178578/

相关文章:

javascript - 如果表单已填写但未提交,浏览器会在离开页面之前提示用户

c# - 在 Asp.Net 中使用电子邮件发送忘记密码

c# - 将 C# 服务引用与代理一起使用

c# - 将 WriteableBitmap 转换为位图以便在 EmguCV 中使用

apache - 仅针对 nginx 上的特定 url 使用 https 重定向

c# - 什么是所有浏览器代理的东西?

c# - OpenXML - 将日期写入 Excel 电子表格会导致内容不可读

Azure IoT 中心 MQTT 用户名和密码字符长度限制

apache - 为什么我的 mod_rewrite 不能像 HTTP 那样用于 HTTPS

javascript - 用于检查 Javascript 对象是否为 html 元素的跨浏览器解决方案