2

I have tried everything regarding the issue I am having with CORS with Web Api 2 and Angular.

I have downloaded the nuget package for CORS for the Web API.

I have enabled CORS in my controllers.

I added the following to my api web.config:

<httpProtocol>
<customHeaders>
  <add name="Access-Control-Allow-Origin" value="*" />
  <add name="Access-Control-Allow-Methods" value="GET, PUT, POST, DELETE, HEAD" />
  <add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />
</customHeaders>
</httpProtocol>

I added the following method to my controller:

 public HttpResponseMessage Options()
    {
        return new HttpResponseMessage { StatusCode = HttpStatusCode.OK };
    }

And I have put the EnableCorsAttribute at the top of the controller.

After this, when I make my POST, I get the following request from within fiddler:

OPTIONS http://api.carb-stage.derivesystems.com/api/Recaptcha/Post HTTP/1.1
Host: api.carb-stage.derivesystems.com
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Access-Control-Request-Method: POST
Origin: http://carb-stage.derivesystems.com
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36
Access-Control-Request-Headers: accept, content-type
Accept: */*
Referer: http://carb-stage.derivesystems.com/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8

And this is the response I get:

HTTP/1.1 503 Service Unavailable
Content-Type: text/html; charset=us-ascii
Server: Microsoft-HTTPAPI/2.0
Date: Tue, 29 Sep 2015 20:10:49 GMT
Connection: close
Content-Length: 326
sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
xaisoft
  • 3,343
  • 8
  • 44
  • 72
  • 1
    Yes, OPTIONS requests are common when dealing with CORS requests. Your question? You have to make sure that your server will respond to the OPTIONS request. – Kevin B Sep 29 '15 at 20:26
  • @KevinB - Is there something I can check to see if my server handles this. DO I have to put something in web.config? or is it a setting in IIS? – xaisoft Sep 29 '15 at 20:42
  • I have no idea as far as what needs to change, i haven't worked with asp.net in quite a while. But i'm pretty sure your server would support it if configured properly. – Kevin B Sep 29 '15 at 20:42
  • Maybe see http://stackoverflow.com/a/14631068/441757 – sideshowbarker Sep 29 '15 at 22:52

0 Answers0