0

Problem statement

What is the best way to dynamically add a client certificate to a HttpClient in C#? I have an application that needs to call the same endpoint with different client certificates (We are calling an API on behalf of our clients).

Scenario:

We are not able to use named HttpClients because our customer base will grow and shrink dynamically. What I had in mind was to create a HttpClientFactory so you could do the following. Doing so creates new problems e.g. socket exhaustion.

var factory = new HttpClientFactory()
var certificate = new X509Certificate2();
HttpClient customerClient = factory.CreateClient(certificate)

Research:

SOK
  • 515
  • 6
  • 21
  • Does this answer your question? [Add client certificate to .NET Core HttpClient](https://stackoverflow.com/questions/40014047/add-client-certificate-to-net-core-httpclient) – SNBS Dec 07 '22 at 07:37
  • Sadly not. I am aware of how to attach a client certificate to a HttpClient. One solution is just to manually create a new HttpClient per request, but it creates new problems e.g. socket exhaustion. – SOK Dec 07 '22 at 07:43

0 Answers0