Enabling Cors with IIS 7.5 WebAPI

Viewed 934

I've been reading a lot about enabling CORS in my Web API Application.

If I run the app in my localhost (with IIS Express) it works. I get the header response Access-Control-Allow-Origin enabling only one origin to GET or POST in the WebAPI. But when I deploy the app to our test server with IIS 7.5. I'm able to do the GET and POST from any origin.

My code looks like this:

Enabling CORS Globally:

    var origin = "http://someorigin:81";
    var corsAttrs = new EnableCorsAttribute(origin, "*", "GET,POST");
    config.EnableCors(corsAttrs);

In my WebConfig I added the following configuration:

  <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />          
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>

I've restarted the IIS also the sites with no success. Also I've tried this solution with no success.

This how my request looks like

Host: http://someorigin:81
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0
Accept: application/json, text/plain, */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Authorization: Bearer ***Token in here***
Referer: http://someorigin:81/site/
Connection: keep-alive
Cache-Control: max-age=0

Please let me know if am I missing something, or there is something else I could do in order to make this work.

0 Answers
Related