简体   繁体   中英

How to add "ignore-certificate-errors" in webview2 WPF

I am trying to convert WPF chrome browser component to WebView2.

Chrome have this settings:

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

How to Add this in WebView2.

I see some links about it,but it say it will be support later microsoft-edge-webview2-ignore-certificate-errors . is this supported?

It is supported in the current release of WebView2 (version 1.0.1343.22).

The way you do it is:

After the WebView2 is initialized, you subscribe to the ServerCertificateErrorDetected event, like this:

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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