I have an MVC application and its associated web API project that are hosted on a remote server in IIS. They have the same application pool. Whenever I try to call the web API from an MVC application, I get a 403 error, which seems to come from the bad credentials passed by the HttpClientHandler. I have
UseDefaultCredentials = true
and I tried to install
Credentials = CredentialCache.DefaultNetworkCredentials
but not one of them allows you to skip the API request.
Setting up the application pool to use my AD username and password allows all API requests to go through, and also call the API directly from Postman to correctly return data.
My guess is that the IIS AppPool [Pool Name] is forwarded in the request, and the proper credentials are never passed. In any case, this does not make the API insecure (for example, only a couple of domain groups should have access to it)?
An example of the call I make in the API from an MVC application
public async Task<HttpResponseMessage> CreateIncident(Incident model) { using (var client = new HttpClient(new HttpClientHandler { UseDefaultCredentials = true })) { var newIncident = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json"); var response = await client.PostAsync(hostUri, newIncident); return response; } }
source share