How to programmatically answer “Yes” to WebBrowser control security alert

拥有回忆 提交于 2019-12-22 10:53:24

问题


I am using WebBrowser control to programmatically access a single website, but whenever I login, I receive this certificate security alert:

Since I trust that website and since I need to programmatically automate the login as well, this dialog box gets in the way.

I searched SO for a solution and found a question similar to mine, but the accepted answer does not work!

I defined a static member in the form that contains the WebControl:

public static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
  return true;
}

In my form's constructor I added:

ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);

But that didn't get rid of the certificate security alert.

I also, clicked the View Certificate button, then clicked the Install Certificate button in the dialog that followed, but that didn't seem to help either.

Is there any way to get rid of this warning?

Is there an IE equivalent to Firefox's Add Security Exception‌​?

Note: The owner's certificate works perfectly fine (without exhibiting this security alert) with standalone browsers (IE, FF, Chrome, Safari). It only exhibits the problem with the WebBroswer control.


回答1:


The best idea is to sort out the broken certificate. Browsers guard these warnings for a reason. What you're doing is trying to circumvent the user's safety.

If you must do this using the webbrowser control, then set ScriptErrorsSuppressed to true.




回答2:


ScriptErrorsSuppressed = True doesn't help: the security dialog does not appear, but the effect is like pressing "No"




回答3:


I solved this by importing the broken certificate in root trusted certification authority.



来源:https://stackoverflow.com/questions/12999735/how-to-programmatically-answer-yes-to-webbrowser-control-security-alert

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!