Sunday, June 2, 2013

Could not establish trust relationship for the SSL/TLS secure channel with authority PC1. (C#)

Overriding errors for trust relationship failures by trusting all certificates

While developing an application, I needed to browse to a url to read a file. Accessing the server url threw a error. So I added a method to trust all certificates from the url before I called the url.. That resolved the issue I was facing.


Code Snippet

Added this code before calling the server url :

// Trust all certificates

System.Net.ServicePointManager.ServerCertificateValidationCallback =
((sender, certificate, chain, sslPolicyErrors) => true);
   

No comments: