title: How to detect SSL Policy errors with .net?
body: <p>I'm totally new to handling policy errors when making web requests so I'm a little bit confused at this point..</p>
  
  <p>I have this task to call a web service but not allow the call to be made if the server I'm calling has an invalid certificate.</p>
  
  <p>So I created a method to call a site with invalid cerificate and using ServerCertificateValidationCallback to prevent the call to be made if the certificate is invalid.</p>
  
  <p>What I need is a quick walkthrough in how to detect the invalid certificate inside my handler. I would have thought that the call to "revoked.badssl.com" would have caused something in the sslPolicyErrors object to be something other than "none" but is this not the case? I see no difference at this point in calling badssl or my other url that has a valid certificate.</p>
  
  <p>For example: if <a href="https://pinning-test.badssl.com/" rel="nofollow noreferrer">https://pinning-test.badssl.com/</a> is opened in chrome it shows a "ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN" (although IE shows the page). How do I find this information that chrome deems as an invalid certificate so I can, if I want to, also handle it as invalid in my code??</p>
  
  <p>This is my code I'm trying with at the moment:</p>
  
  <pre><code>ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) =&gt;
      {
        if(someError?!)
          return false;
  
        return true;
      };
  
      using (HttpClient client = DefaultHttpClient())
      {
        Uri uri = new Uri("https://revoked.badssl.com/");
        string jsonObj = "{}";
        var content = new StringContent(jsonObj, Encoding.UTF8, "application/json");
        HttpResponseMessage response = client.PostAsync(uri, content).Result;
      }
  </code></pre>