从 Web 浏览器控件打开证书信息
有谁知道如何从 WebBrowser
控件打开基于 SSL 的“证书信息”屏幕?
Does anyone know how to open up the "Certificate Information" screen based on the SSL from the WebBrowser
control?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这可以通过使用名为
X509Certificate2UI
的类来实现。要使此类可供您使用,您需要添加对 System.Security.dll 的引用
在
X509Certificate2UI
类中,您有一个名为DisplayCertificate()< 的方法/code> 接受
X509Certificate2
对象作为参数。调用时,此方法会显示一个对话框,其中显示所有证书信息(包括链接),与 IE 中的对话框完全相同。Web浏览器控件只能返回一个
X509Certificate
,然后可以将其传递到X509Certificate2
类的构造函数中。所以代码看起来像这样:
This can be achieved by using a class called
X509Certificate2UI
.To make this class avalable to you, you need to add a reference to
System.Security.dll
In the
X509Certificate2UI
class you have a meyhod calledDisplayCertificate()
which takes anX509Certificate2
object as a parameter. When invoked, this method shows a dialog box displaying all cert information including chaining, exactly the same as the dialog box you will find in IE.The webbrowser control can only return a
X509Certificate
which can then be passed into the constructor of theX509Certificate2
class.So the code looks as such:
如果我理解正确,您应该不在
WebBrowser
中搜索此信息,而是在 CryptoAPI 中搜索。 Cryptui.dll 中存在诸如CryptUIDlgSelectCertificateFromStore
、CryptUIDlgViewContext
之类的函数。 WINTRUST.DLL中有一些函数,例如WinVerifyTrustEx
,也可以显示一些对话框。您能否准确描述我如何在 Internet Explore 中显示您想要的对话框?您是否已使用
WebBrowser
控件工作,那么您可以在BeforeNavigate2
事件内部跟踪 Internet Explorer 具有的 url。有了这个 URL,您就可以下载 SSL 证书并在CryptUIDlgViewContext
方面进行显示。要下载或获取证书,您可以使用带有 INTERNET_OPTION_SERVER_CERT_CHAIN_CONTEXT 或 INTERNET_OPTION_CLIENT_CERT_CONTEXT 标志的 InternetQueryOption。可以是来自 INTERNET_OPTION_SECURITY_CERTIFICATE、INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT 的信息(请参阅 http://support.microsoft.com/kb/ 251347)对你来说就足够了。If I understand you correct you should search for this information not in
WebBrowser
but inside of CryptoAPI. Exist such function likeCryptUIDlgSelectCertificateFromStore
,CryptUIDlgViewContext
from Cryptui.dll. There are some functions in WINTRUST.DLL likeWinVerifyTrustEx
which can also display some dialogs.Could you exactly describe how I can display dialog what you want in Internet Explore? Do you works already with
WebBrowser
control, then you can trace, for example, inside ofBeforeNavigate2
Event the url which Internet Explorer has. Having this URL you can download SSL certificate an display if with respect ofCryptUIDlgViewContext
. To download or get the certificate you can use InternetQueryOption with INTERNET_OPTION_SERVER_CERT_CHAIN_CONTEXT or INTERNET_OPTION_CLIENT_CERT_CONTEXT flag. It can be that information from INTERNET_OPTION_SECURITY_CERTIFICATE, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, (see http://support.microsoft.com/kb/251347) will be enough for you.虽然它不使用 .NET WebBrowser,但您可以针对标准 WebBrowser 利用此 C# 包装器代码,而不会对您的项目产生太大影响:
http://code.google.com/p/csexwb2/
然后,您只需说
ShowCertificateDialog()
就无法执行 ExecWB 或调用否则该对话框。
While it's not using the .NET WebBrowser, you could leverage this C# wrapper code against the standard WebBrowser without much impact on your project:
http://code.google.com/p/csexwb2/
It will then require you only to say
ShowCertificateDialog()
There is no way to do an ExecWB or invoke that dialog otherwise.