在何处放置RemoteCertificateValidationCallback? [英] Where to place RemoteCertificateValidationCallback?
问题描述
我这里有同样的问题:如何禁用安全警报窗口WebBrowser控件中
I have the same problem as here: How to disable "Security Alert" window in Webbrowser control
我喜欢的答案,但我要去哪里放置 ServicePointManager.ServerCertificateValidationCallback =新RemoteCertificateValidationCallback(ValidateServerCertificate);
I like the answer, but where am I going to place the ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);
?
我得到的无效证书的消息提交我校网络的登录页面,此代码后,
I get the 'Invalid certification' message after I submit the login page of my school network with this code:
HtmlElementCollection ellements = webBrowser.Document.GetElementsByTagName("input");
foreach (HtmlElement ellement in ellements)
{
if (ellement.OuterHtml == "<INPUT onclick=\"this.value = 'Submitted'\" value=\" Login \" type=submit>")
{
ellement.InvokeMember("click");
this.DialogResult = DialogResult.OK;
break;
}
}
非常感谢你。 :)
Thank you very much. :)
推荐答案
您应该把下面的位于任何点显示您的Web浏览器控件之前/提交页面:
You should put the following at any point before you show the web browser control / submit the page:
ServicePointManager.ServerCertificateValidationCallback +=
new RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => { return true; });
(这是完全一样的链接的问题的示例的答案,但回调方法是匿名所以它的一个小更紧凑)。
(This is exactly the same as the example answer in the linked question, but the callback method is anonymous so its a little more compact).
这篇关于在何处放置RemoteCertificateValidationCallback?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!