0

I have a frontend web app which uses nodejs on the server and angularjs in the client running locally on port 5000. The client code needs to make an ajax request to a separate Web API service also running locally but on a different port hosted in IIS 6.2. This makes it a cross-origin request, for which the browser is trying to make a preflight request. However, the preflight fails and the ajax error handler gets invoked, the status code of the response is -1, and the Chrome console shows that the preflight check failed with presumably the standard error message of Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://localhost:5000' is therefore not allowed access. The response had HTTP status code 500.

As far as I can tell, I have CORS enabled in my Web API service. here's the very beginning of my Application_Start method:

var corsAttr = new EnableCorsAttribute("*", "*", "*");
config.EnableCors(corsAttr);

config.MapHttpAttributeRoutes();
// etc...

This exact setup is working fine on my colleagues' machines, so there's something going on with my machine specifically. I'm stumped, any ideas on what might be going on? I'm guessing something is just misconfigured somewhere.

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
gzak
  • 3,908
  • 6
  • 33
  • 56
  • What do you thing in response in the preflight request? Is there Access-Control-Allow-Origin with your doman name? – Errorpro Nov 04 '15 at 17:59

1 Answers1

0

Avoid using wild cards ('*') and just try with this one.

var corsAttr = new EnableCorsAttribute("https://localhost", "", "");

just substitute the wild card with your domain.

How to allow CORS?

Community
  • 1
  • 1
Mohanavel T
  • 371
  • 4
  • 17