title: C# Http request with client certificates returns 500
body: <p>I am trying to send a rest call by passing client certificate to the HttpClientHandler but I am getting a 500 Internal Server Error back:</p>
  <pre><code>var cert = X509Certificate2.CreateFromPemFile(&quot;C:\\work\\certs\\pwm-acc.pem&quot;, &quot;C:\\work\\certs\\pwm-acc.key&quot;);
  using var handler = new HttpClientHandler();
  handler.ClientCertificates.Clear();
  handler.ClientCertificates.Add(cert);
  
  _httpClient = new HttpClient(handler)
  {
      BaseAddress = new Uri(&quot;https://pwm.intranet/ServiceCert/api/&quot;)
  };
  
  var restOfUrl = $&quot;Accounts?AppID={AppId}&quot;;
  using var request = new HttpRequestMessage(HttpMethod.Get, restOfUrl);
  
  try
  {
      using var response = await _httpClient.SendAsync(request, cancellationToken).ConfigureAwait(false);
  
      response.EnsureSuccessStatusCode();
      var result = await response.Content.ReadFromJsonAsync&lt;AIMResponse&gt;(cancellationToken: cancellationToken);
      return result;
  }
  catch (HttpRequestException ex)
  {
      _logger.LogDebug(ex, &quot;API request failed.&quot;, request);
      throw;
  }
  </code></pre>
  <p>The response I am getting is:
  <code>Response status code does not indicate success: 500 (Internal Server Error).</code></p>
  <p>The response content contains a HTML error page:</p>
  <pre><code>&lt;b&gt; Description: &lt;/b&gt;An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
   &lt;br&gt;&lt;br&gt;
   &lt;b&gt;Details:&lt;/b&gt; To enable the details of this specific error message to be viewable on remote machines, please create a &amp;lt;customErrors&amp;gt; tag within a &amp;quot;web.config&amp;quot; configuration file located in the root directory of the current web application. This &amp;lt;customErrors&amp;gt; tag should then have its &amp;quot;mode&amp;quot; attribute set to &amp;quot;Off&amp;quot;.&lt;br&gt;&lt;br&gt;
  </code></pre>
  <p>The same API call, but using curl works:</p>
  <p><code>curl --cert /etc/pki/tls/certs/pwm-acc.pem --key /etc/pki/tls/certs/pwm-acc.key &quot;https://pwm.intranet/ServiceCert/api/Accounts?AppID=DUMMYID&quot; --verbose</code></p>
  <pre><code>&lt; HTTP/1.1 200 OK
  &lt; Cache-Control: no-cache
  &lt; Pragma: no-cache
  &lt; Content-Type: application/json; charset=utf-8
  &lt; Expires: -1
  &lt; Server: Microsoft-IIS/10.0
  &lt; Strict-Transport-Security: max-age=15552001; includeSubDomains; preload
  &lt; Date: Tue, 04 Jan 2022 17:37:44 GMT
  &lt; Content-Length: 503
  </code></pre>
  <p>What am I doing wrong?</p>