C# Ignore certificate errors?

JL. picture JL. · Apr 20, 2010 · Viewed 221.1k times · Source

I am getting the following error during a web service request to a remote web service:

Could not establish trust relationship for the SSL/TLS secure channel. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.

Is there anyway to ignore this error, and continue?

It seems the remote certificate is not signed.

The site I connect to is www.czebox.cz - so feel free to visit the site, and notice even browsers throw security exceptions.

Answer

Peter Lillevold picture Peter Lillevold · Apr 20, 2010

Add a certificate validation handler. Returning true will allow ignoring the validation error:

ServicePointManager
    .ServerCertificateValidationCallback += 
    (sender, cert, chain, sslPolicyErrors) => true;