C# – How to disable “Security Alert” window in Webbrowser control


I'm using Webbrowser control to login to HTTPS site with "untrusted certificate".
but I get popup such standart window "Security Alert" about untrusted certificate:

Security Alert window

I have to find this window by title and send it Alt+Y to press Yes:

int iHandle = NativeWin32.FindWindow(null, "Security Alert");

but user can see a flickering of this window.

How can I ignore this alert?
Or disable this "untrusted certificate" check in Webbrowser control?

Best Answer

This should do it:

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

ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);

Obviously, blindingly allowing certificates is a security risk. Be careful.