title: ASP.NET Core pass default credentials to HttpClient
body: <p>How to pass DefaultCredentials in ASP.NET Core to the HttpClient?</p>
  
  <p>It works fine when I run it locally in VisualStudio. The current user is authorized to request "www.mycompany.com". But as soon as I publish it to the IIS I get an 401 (Unauthorized) because HttpClient get the web-server-user (not authorized) in DefaultCredentials.</p>
  
  <p>Windows-Authentification is active in VisualStudio and on IIS.</p>
  
  <p>My c# code:</p>
  
  <pre><code>HttpClient Client = new HttpClient(new HttpClientHandler() { UseDefaultCredentials = true });
  Client.BaseAddress = new Uri("www.mycompany.com");
  Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  Client.DefaultRequestHeaders.Add("Application-Name", Assembly.GetExecutingAssembly().GetName().Name);
  
  HttpResponseMessage response = Client.GetAsync("/classes").Result;
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>I understand that locally it runs with current user, but I don't know how to authorize the Application Pool...</p>
  
  <p><strong>EDIT2</strong></p>
  
  <p>I didn't quite explain it correctly. I want to pass-trough the authentication from the local user to the HttpClient. <strong>Only local users are authorized to make a request</strong></p>