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.
In order to enable CORS (Cross Origin Resource Sharing) in my controller, I implemented the OPTION action:
[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;
}
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:
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
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:
res.Headers.Add("X-App-Limit-Remaining", getRemainingCalls());
Anybody knows how to overwrite/change HTTP headers from a C# WEB API hosted by IIS 8. ?
Many Thanks,
Luke