【发布时间】:2018-03-23 14:51:05
【问题描述】:
我的站点有一个测试环境和一个生产环境,我不确定这是否只是我的证书的问题。我的测试环境有一个我使用 digicert 生成的真实证书,但我确实在浏览器信息中看到它显示“您与此站点的连接并不完全安全。”
我正在使用 WebBrowser 在我的网站上生成一个页面并将其转换为可下载的图像,这是基本代码:
using (var webBrowser = new WebBrowser {ScrollBarsEnabled = false, ScriptErrorsSuppressed = true}){
webBrowser.Navigate(_url);
while (webBrowser.ReadyState != WebBrowserReadyState.Complete){
System.Windows.Forms.Application.DoEvents();
Thread.Sleep(5);
}
while (!(bool)webBrowser.Document.InvokeScript("getDataIsReady"))
{
// Exit if requested
if (ct.IsCancellationRequested)
{
ct.ThrowIfCancellationRequested();
}
System.Windows.Forms.Application.DoEvents();
Thread.Sleep(15);
}
// Slight pause because sometimes there is a few milliseconds before the GMAP tiles are completely loaded after the "tilesloaded" event fires
Thread.Sleep(200);
// Set the size of the WebBrowser control
webBrowser.Width = _width < 1 ? webBrowser.Document.Body.ScrollRectangle.Width : _width;
webBrowser.Height = _height < 1 ? webBrowser.Document.Body.ScrollRectangle.Height : _height;
// Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control
bitmap = new Bitmap(webBrowser.Width, webBrowser.Height);
webBrowser.DrawToBitmap(bitmap, new Rectangle(0, 0, webBrowser.Width, webBrowser.Height));
当我通过 http 运行它时,文档会加载,但通过 https,当我检查 webBrowser.Document 时,我看到标题是“导航已取消”。
这是我的证书问题还是 WebBrowser 方法的问题?我希望当我将它推送到具有真正 SSL 证书的 Prod 时,它会起作用,但我不想部署它然后发现它在那里也不起作用。
【问题讨论】:
-
忽略损坏证书的简单方法是使用 Fiddler,将其配置为解密 SSL 并忽略证书错误(不会帮助 Firefox,但应该适用于 Edge/IE/Chrome 以及 .Net WebBrowser )。作为副作用,您将看到所有使调试更容易的请求。
标签: c# ssl https webbrowser-control