Ignore Ssl validation error while connecting to https endpoint

Scenario:

Ignore Ssl validation error while connecting to https endpoint.

Solution:

  • Ignore ssl validaton errors and continue. In cases where the endpoints are internal only and so CA(Certificating Authority) wont verify and issue a SSL. In such cases certificate used is self-signed one. Below is setting at instance level. Add this before creating HttpClient.
    1. 1
      2
      3
      4
      5
      6
      7
      var handler = new HttpClientHandler();
      
                          handler.SslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12;
                          handler.ServerCertificateCustomValidationCallback = delegate { return true; };
      
                      
      var httpClient= new HttpClient(handler);
  • Ignore ssl validaton errors and continue. In cases where the endpoints are internal only and so CA(Certificating Authority) wont verify and issue a SSL. In such cases certificate used is self-signed one. Below is the global change. Add this before creating HttpClient.
    1
    2
    3
    4
    5
    // wrap this in config
    
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                    ServicePointManager.ServerCertificateValidationCallback +=
                        (sender, cert, chain, sslPolicyErrors) => true;

No comments:

Post a Comment

Move Github Sub Repository back to main repo

 -- delete .gitmodules git rm --cached MyProject/Core git commit -m 'Remove myproject_core submodule' rm -rf MyProject/Core git remo...