Configures .Net to trust all certificates when making network calls

 

/// <summary>
/// Configures .Net to trust all certificates when making network calls. This is used so that calls
/// to an https SharePoint server without a valid certificate are not rejected. This should only be used during
/// testing, and should never be used in a production app.
/// </summary>
public static void TrustAllCertificates()
{
//Trust all certificates
ServicePointManager.ServerCertificateValidationCallback =
((sender, certificate, chain, sslPolicyErrors) => true);
}

 

 

 

System.Net.ServicePointManager.ServerCertificateValidationCallback +=
delegate (object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate,
System.Security.Cryptography.X509Certificates.X509Chain chain,
System.Net.Security.SslPolicyErrors sslPolicyErrors)
{
return true; // **** Always accept
};

Configures .Net to trust all certificates when making network calls