title: Angular Post to Asp.Net (not Core) Web Api Error 415 on IIS
body: <p>I'm going completely nuts in making a simple Web Api call to work and I'm quite frustrated because things are much more complicated than they should be.</p>
  
  <p>I created an extremely simple Web Api (for testing) that is consumed by an Angular 6 client and I was able to make it to work if I self-host it locally but if I publish it to my Win10 local IIS (that is the way it will work when deployed to a server) then the request to Web Api fails with error 415 "Unsupported Media Type".</p>
  
  <p>The weird thing is that if I make the request to the self-hosted Web Api (which works) browser network tab is quite different than requesting to IIS published version.</p>
  
  <p>This is my Web Api method:</p>
  
  <pre><code>[HttpPost]
  [HttpOptions]
  public void Post([FromBody]Credentials cred)
  {
      string strTest = "I'm doing just nothing";
  }
  </code></pre>
  
  <p>I have to mention that it took me a whole morning to make it to work even self-hosted because of CORS and the key was adding the [HttpOptions] in method header.</p>
  
  <p>Class Credentials:</p>
  
  <pre><code>public class Credentials {
      public string Username { get; set; }
      public string Password { get; set; }
  }
  </code></pre>
  
  <p>Angular post code:</p>
  
  <pre><code>let headers={
      headers: new HttpHeaders({
          'Accept': 'application/json',
          'Content-Type': 'application/json; charset=UTF-8'
      })
  }
  
  return this.http.post&lt;any&gt;('http://localhost:9810/api/Login', JSON.stringify({username, password}), headers) ...
  </code></pre>
  
  <p>Network tab info when self-hosted (working one):</p>
  
  <pre><code>General:
  Request URL: http://localhost:9000/api/Login
  Request Method: OPTIONS
  Status Code: 204 No Content
  Remote Address: [::1]:9000
  Referrer Policy: no-referrer-when-downgrade
  
  Response Headers:
  Content-Length: 0
  Date: Thu, 30 Aug 2018 09:24:50 GMT
  Server: Microsoft-HTTPAPI/2.0
  
  Request Headers:
  Accept: */*
  Accept-Encoding: gzip, deflate, br
  Accept-Language: es-ES,es;q=0.9,en;q=0.8
  Access-Control-Request-Headers: content-type
  Access-Control-Request-Method: POST
  Connection: keep-alive
  Host: localhost:9000
  Origin: http://localhost:4200
  User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36
  </code></pre>
  
  <p>Network tab info when published to local IIS (NOT working one):</p>
  
  <pre><code>General:
  Request URL: http://localhost:9810/api/Login
  Request Method: OPTIONS
  Status Code: 415 Unsupported Media Type
  Remote Address: [::1]:9810
  Referrer Policy: no-referrer-when-downgrade
  
  Response Headers:
  Content-Length: 801
  Content-Type: application/json; charset=utf-8
  Date: Thu, 30 Aug 2018 08:57:58 GMT
  Server: Microsoft-IIS/10.0
  X-Powered-By: ASP.NET
  
  Request Headers:
  Accept: */*
  Accept-Encoding: gzip, deflate, br
  Accept-Language: es-ES,es;q=0.9,en;q=0.8
  Access-Control-Request-Headers: content-type
  Access-Control-Request-Method: POST
  Connection: keep-alive
  Host: localhost:9810
  Origin: http://localhost:4200
  User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36
  </code></pre>
  
  <p>So, as you see, when the Web Api is published to IIS the output in network tab is different and the header is not arriving.</p>
  
  <p>I'm completely stuck and frustrated my friends. Please help.</p>
  
  <p>Edit 1: I add my WebApiConfig where you can see I enable cors just in case.</p>
  
  <pre><code>public static class WebApiConfig
  {
      public static void Register(HttpConfiguration config)
      {
          var cors = new EnableCorsAttribute("http://localhost:4200", "*", "*");
          config.EnableCors(cors);
      }
  }
  </code></pre>