ih8ie8 ih8ie8 - 1 month ago 9
C# Question

How to programmatically answer "Yes" to WebBrowser control security alert

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

enter image description here

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.

Answer

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.