Click here to Skip to main content
16,018,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
I know its not a big issue to resolve ,But i am facing problem to consume web api in asp.net MVC web api.

I am getting below error:
"XMLHttpRequest cannot load http://192.168.1.71:800/api/IzoGlass/ToolLocationData. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:58469' is therefore not allowed access".

I've searched and find solution but not working fine with my application.

Description :-When i am consuming web api from same domain in my application its working fine.

but whenever i am consuming webapi from other domain its throwing error. given above.


What I have tried:

I've used this code inside webapi.config file.

var cors = new EnableCorsAttribute("http://192.168.1.71", "*", "*");
config.EnableCors(cors);
Posted
Updated 11-Jul-16 0:03am

1 solution

Enabling Cross-Origin Requests in ASP.NET Web API 2 | The ASP.NET Site[^]

The origin you need to enable is the address of the client, so "http://localhost:58469" in your case, not 192.168.1.71, or you could use a * to enable all origins which might be useful as a test but maybe not ideal for production use. However you wouldn't want to code your webapi to your dev webserver address either as that will change.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900