I have a simple asp.net core 2.0 WebApi app running in Kestrel behind an IIS reverse proxy. The single route is pretty simple, it just makes a http request:
using (HttpClient client = new HttpClient())
{
client.BaseAddress = new Uri("http://www.google.ca");
HttpResponseMessage response = await client.GetAsync("/search?q=test&oq=test");
return Ok();
}
However, this request consistently takes 2-3 seconds to complete. Yet, if I run Kestrel directly without IIS, the same code takes ~100ms.
I followed all the Microsoft docs for configuring kestrel with IIS.
TL;DR Needed to configure HttpClient to not use the default proxy settings
HttpClientHandler clientHandler = new HttpClientHandler();
clientHandler.UseProxy = false;
using (HttpClient client = new HttpClient(clientHandler))
{ ... }
The long explanation is that asp.net attempts to use the machine's default proxy configuration settings for each request. My IIS is configured to run under the Network Service account which has limited access, and as such, will eventually fail (presumably because it doesn't have access to the registry) to find the proxy settings and just connect directly. This process apparently takes about 2.5 seconds.
For my kestrel tests, I was running dotnet .\api.dll from the command line, which uses my logged in credentials, and could successfully access the proxy settings. However, when using IIS, it spawns the dotnet process under the same Network Service account that IIS is running as.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With