Nico
Nico

Reputation: 263

How to make HttpClient to use the app pool identity

I'm trying to make an http call from website A to website B, using the website A's identity.

Using .Net fwk 4.x, I just have to make something like that:

using (var client = new HttpClient(new HttpClientHandler { UseDefaultCredentials = true }) {
   // Do something
}

In aspnetcore 2.2, an IHttpClientBuilder has been provided to manage http clients.

The same code is supposed to look to something like this:

services.AddHttpClient("myOtherSite", httpClient => {
                httpClient.BaseAddress = new Uri("http://something");
            })
            .ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler {
                UseDefaultCredentials = true
            });

Then I just need to inject the IHttpBuilder where I need a client then call clientBuilder.buildClient("myOtherSite").

Using this, http request seems to be made without the pool user, despite the documentation..

Has someone done something like this?

Upvotes: 0

Views: 1545

Answers (1)

Jeff LaFay
Jeff LaFay

Reputation: 13350

I'm not sure if this is your issue but this Microsoft Documentation states that starting with core 2.1, the System.Net.Http.SocketsHttpHandler class is used instead.

It has information on how to configure to allow continuing use of HttpClientHandler but you may want to switch or even try using HttpMessageHandler in place of the type you're using for the handler currently.

Upvotes: 1

Related Questions