title: 401 Unauthorized error when accessing webapi from angular
body: <p>I need to capture a user's domain\username when they access my webapi app. On my dev machine I have my webapi at <code>localhost:10570</code> and my angularjs website which makes calls to the webservice at <code>localhost:34575</code>.</p>
  
  <p>If I make a call directly to my webapi app everything works fine. I can see the users domain and username and the service returns the requested data as JSON. But if I access my angularjs site and angular makes the call to webapi then I get 401 unauthorized for every call against the service.</p>
  
  <p>In my WebApi app's web.config I have:</p>
  
  <pre><code>&lt;system.web&gt;
      &lt;compilation debug="true" targetFramework="4.5.2" /&gt;
      &lt;httpRuntime targetFramework="4.5.2" /&gt;
      &lt;authentication mode="Windows" /&gt;
    &lt;/system.web&gt;
    &lt;system.webServer&gt;
      &lt;httpProtocol&gt;
    &lt;customHeaders&gt;
      &lt;add name="Access-Control-Allow-Origin" value="http://localhost:34575" /&gt;
      &lt;add name="Access-Control-Allow-Methods" value="POST, PUT, DELETE, GET, OPTIONS" /&gt;
      &lt;add name="Access-Control-Allow-Headers" value="content-Type, accept, origin, X-Requested-With, Authorization, name" /&gt;
      &lt;add name="Access-Control-Allow-Credentials" value="true" /&gt;
    &lt;/customHeaders&gt;
  &lt;/system.webServer&gt;
  </code></pre>
  
  <p>I have this in IIS Express for Visual Studio 2015's applicationhost.config file:</p>
  
  <pre><code>&lt;location path="MyNamespace.WebAPI"&gt;
      &lt;system.webServer&gt;
          &lt;security&gt;
              &lt;authentication&gt;
                  &lt;windowsAuthentication enabled="true" /&gt;
                  &lt;anonymousAuthentication enabled="false" /&gt;
              &lt;/authentication&gt;
          &lt;/security&gt;
      &lt;/system.webServer&gt;
  &lt;/location&gt;
  </code></pre>
  
  <p>My angularjs site is part of the same solution at "MyNamespace.Client".</p>
  
  <p>Why does accessing the web service directly work fine, but accessing it via the angular app fail?</p>