这可以通过使用一个名为的类来实现X509Certificate2UI.
要使此类可用,您需要添加引用 System.Security.dll
在X509Certificate2UI类中,你有一个meyhod调用DisplayCertificate(),它将一个X509Certificate2对象作为参数.调用时,此方法显示一个对话框,显示所有证书信息,包括链接,与您在IE中找到的对话框完全相同.
webbrowser控件只能返回一个X509Certificate然后可以传递给X509Certificate2类的构造函数的控件.
所以代码看起来像这样:
//includes on top
using System.Security;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
//Do webrequest to get info on secure site
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://securesite.com");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
response.Close();
//retrieve the ssl cert and assign it to an X509Certificate object
X509Certificate cert = request.ServicePoint.Certificate;
//convert the X509Certificate to an X509Certificate2 object by passing it into the constructor
X509Certificate2 cert2 = new X509Certificate2(cert);
//display the cert dialog box
X509Certificate2UI.DisplayCertificate(cert2);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9471 次 |
| 最近记录: |