如何在WPF WebBrowser控件中允许不受信任的SSL

时间:2017-07-13 05:57:57

标签: c# wpf ssl

我正在做一个非常小的应用程序,必须显示一些网页(如" kiosk")。我所使用的部分网页只能通过HTTPS访问,但却没有有效的SSL证书。

有没有办法强制WPF <Grid> <WebBrowser helpers:WebBrowserUtility.BindableSource="{Binding UrlToDisplay}" AllowInvalidSSL="true"></WebBrowser> </Grid> 控件允许任何SSL证书?

类似的东西:

# In Python 3.x

hash={'a': 1, 'b': 2}

for k in hash:
    print (str(k) + "," + str(hash[k]))

# OR
for key, value in hash.items():
    print (str(key) + ',' + str(value))

# OR
for key, value in {'a': 1, 'b': 2}.items():
    print (str(key) + ',' + str(value))

# OR
for tup in hash.items():
    print (str(tup[0]) + ',' + str(tup[1]))

如果没有,你能想到另一种选择吗?

1 个答案:

答案 0 :(得分:0)

不确定您是否可以使用WPF WebBrowser解决它。但是,如果您使用CefSharp.Wpf,则可以轻松实施IRequestHandler并查看不受信任的网站,而不会被用户注意。

bool IRequestHandler.OnCertificateError(IWebBrowser browserControl, IBrowser browser, CefErrorCode errorCode, string requestUrl, ISslInfo sslInfo, IRequestCallback callback)
{
    if (!callback.IsDisposed)
    {
        using (callback)
        {
            callback.Continue(true);
            return true;
        }
    }

    return false;
}

取自this example。适合我。