简体   繁体   English

如何在 webview2 WPF 中添加“忽略证书错误”

[英]How to add "ignore-certificate-errors" in webview2 WPF

I am trying to convert WPF chrome browser component to WebView2.我正在尝试将 WPF chrome 浏览器组件转换为 WebView2。

Chrome have this settings: Chrome 有这样的设置:

        if (Cef.IsInitialized == false)
        {
            var settings = new CefSettings();
            settings.IgnoreCertificateErrors = true;
            Cef.Initialize(settings);
        }

How to Add this in WebView2.如何在 WebView2 中添加它。

I see some links about it,but it say it will be support later microsoft-edge-webview2-ignore-certificate-errors .我看到一些关于它的链接,但它说它将在以后支持microsoft-edge-webview2-ignore-certificate-errors is this supported?这支持吗?

It is supported in the current release of WebView2 (version 1.0.1343.22).当前版本的WebView2 (版本 1.0.1343.22)支持它。

The way you do it is:你这样做的方式是:

After the WebView2 is initialized, you subscribe to the ServerCertificateErrorDetected event, like this: WebView2初始化后,订阅ServerCertificateErrorDetected事件,如下所示:

webView.CoreWebView2.ServerCertificateErrorDetected += WebView_ServerCertificateErrorDetected;

then inside that eventhandler, you tell it to ignore the error:然后在该事件处理程序中,您告诉它忽略错误:

void WebView_ServerCertificateErrorDetected(object sender, CoreWebView2ServerCertificateErrorDetectedEventArgs e)
{
   CoreWebView2Certificate certificate = e.ServerCertificate;
   e.Action = CoreWebView2ServerCertificateErrorAction.AlwaysAllow;
}

There's more advanced options available (like only ignore some certificates), but if you just want to allow all certificates, then this should work.有更高级的选项可用(例如只忽略某些证书),但如果您只想允许所有证书,那么这应该可以工作。

However the question still remains: Why are the certificates invalid and should they be ignored?然而问题仍然存在:为什么证书无效并且应该被忽略? You can make even self-signed certificates valid on local systems, so they don't throw errors (look it up).您甚至可以使自签名证书在本地系统上有效,因此它们不会引发错误(查找)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM