Muhammed Eassa
Muhammed Eassa

Reputation: 11

WebAPI error when calling from Angular after hosting on IIS (Post method only)

My ASP.NET WebAPI call was working perfectly when hosted in debugging mode (I can call from angular, post man etc. with no issues found).

When I host the same WebAPI on IIS and call post methods from Angular, it's giving me an error (I have no issues with the get method). Post and get are working even when calling from post man tool.

192.168.100.12:89/api/Booking/schedules/:1 Failed to load resource: the server responded with a status of 404 (Not Found)

Access to XMLHttpRequest at 'http://192.168.100.12:89/api/Booking/schedules/' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Upvotes: 1

Views: 1139

Answers (1)

jle
jle

Reputation: 9489

You are trying to access the url at 192.168.100.12 from localhost:3000. Since they are not at the same address, it is considered cross-origin. By default these requests are blocked as a security measure.

  • If you are using Angular (not angularjs), you can set up a proxy to forward requests during development. See this question for setting up a proxy.
  • Alternatively, you can add a DEBUG flag that will disable your CORS policy.

Upvotes: 0

Related Questions