title: Adding custom headers in .NET WebAPI 2 hosted by IIS 8.5
body: <p>I wrote a WEBAPI application with C# that works fine while developing but when in production, hosted by IIS 8.5 I got a problem.</p>
  
  <p>In order to enable CORS (Cross Origin Resource Sharing) in my controller, I implemented the OPTION action:</p>
  
  <pre><code>[HttpOptions]
  [AllowAnonymous]
  public HttpResponseMessage Options()
  {
      HttpResponseMessage res = new HttpResponseMessage();
  
      res.Headers.Add("Access-Control-Allow-Headers", "User-Agent, Content-Type, Accept, X-ApplicationId, Authorization, Host, Content-Length");
      res.Headers.Add("Access-Control-Allow-Methods", "POST");
      res.Headers.Add("Access-Control-Allow-Origin", "*");
      res.StatusCode = HttpStatusCode.OK;
      return res;
  }
  </code></pre>
  
  <p>As I wrote before everything works ok on Visual Studio but in production, when I make an OPTIONS request using Fiddler, the answer is always:</p>
  
  <pre><code>HTTP/1.1 200 OK
  Allow: OPTIONS, TRACE, GET, HEAD, POST
  Server: Microsoft-IIS/8.5
  Public: OPTIONS, TRACE, GET, HEAD, POST
  X-Powered-By: ASP.NET
  Date: Fri, 05 Feb 2016 16:56:20 GMT
  Content-Length: 0
  Proxy-Connection: keep-alive
  </code></pre>
  
  <p>I know that is possible to add Header's key statically in IIS but, in my controller, I need to add a Custome Header with dynamic values like that:</p>
  
  <pre><code>res.Headers.Add("X-App-Limit-Remaining", getRemainingCalls());
  </code></pre>
  
  <p>Anybody knows how to overwrite/change HTTP headers from a C# WEB API hosted by IIS 8. ?</p>
  
  <p>Many Thanks,</p>
  
  <p>Luke</p>