title: CORS not working - 401
body: <p>Trying to fetch data from a WebApi. Here's the service call in TypeScript:</p>
  
  <pre><code>GetStatus(hostName: string): any {
      this.Http.post(this.ServiceBaseAddress)
          .success(data =&gt; {
              return data;
          });
  }
  </code></pre>
  
  <p>On the server side, I have done the following to enable CORS:</p>
  
  <p>1: Add NugetPackage <code>Microsoft.ASP.Net.Cors</code></p>
  
  <p>2: Add the EnableCors Attribute to one Controller (which I'm trying to call)</p>
  
  <pre><code>[EnableCors("*", "*", "*")]
  public class DeployController : ApiController
  { //...
  }
  </code></pre>
  
  <p>3: Enable CORS in the WebApiConfig</p>
  
  <pre><code>public static class WebApiConfig
  {
    public static void Register(HttpConfiguration config)
    {
      config.EnableCors(); //...
  </code></pre>
  
  <p>4: Add custom Headers via Web.config (in the system.webServer region)</p>
  
  <pre><code>&lt;httpProtocol&gt;
    &lt;customHeaders&gt;
      &lt;add name="Access-Control-Allow-Origin" value="*" /&gt;
      &lt;add name="Access-Control-Allow-Methods" value="GET, POST, OPTIONS, PUT, DELETE" /&gt;
    &lt;/customHeaders&gt;
  &lt;/httpProtocol&gt;
  </code></pre>
  
  <p>I noticed that Fiddler seems to do some really nasty caching, which got me confused more than once...Now, at least, I get a response which has the following headers:</p>
  
  <pre><code>HTTP/1.1 401 Unauthorized
  Cache-Control: private
  Content-Type: text/html; charset=utf-8
  Server: Microsoft-IIS/10.0
  X-SourceFiles: =?UTF-8?B?QzpcRGV2ZWxvcFxTUEFSQ1xEZXZlbG9wXFJ1bnRpbWVcU1BBUkMuTWFuYWdlbWVudEFwaVxNYW5hZ2VtZW50QXBpXGFwaVxkZXBsb3lcZ2V0aG9zdHM=?=
  WWW-Authenticate: Negotiate
  WWW-Authenticate: NTLM
  X-Powered-By: ASP.NET
  Access-Control-Allow-Origin: *
  Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE
  Date: Mon, 30 Nov 2015 13:12:48 GMT
  Content-Length: 6540
  Proxy-Support: Session-Based-Authentication
  </code></pre>
  
  <p>The content of the response is the 401 Error site of the service.</p>
  
  <p>To get this working, I tried to add anonynous authentication to the WebApis Web.config, but without success:</p>
  
  <pre><code>&lt;authorization&gt;
    &lt;allow users="*"/&gt;
  &lt;/authorization&gt;
  </code></pre>
  
  <p>Any Ideas what I could do? How do I authenticate?</p>
  
  <hr>
  
  <p><strong>EDIT:</strong> 
  Turns out this is really an authentication Problem. The WebApi Authentication is set as follows:</p>
  
  <pre><code>&lt;authentication mode="Windows" /&gt;
  </code></pre>
  
  <ul>
  <li>When I call the Webservice URI in IE or Chrome, I get the expected response.</li>
  <li>When I call it in Firefox and press cancel instead of entering my user credentials, I get the same Message that the http call from my website gets - 
  an issue with 401.2 Authentication Headers.</li>
  </ul>
  
  <p>That being said, I need to know how to tell the angular Ajax call to use my credentials.</p>