Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
C#
XMLHttpRequest cannot load "dev server deployed Web Api". No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '""' is therefore not allowed access


I build the application using WebApi, HTML, JS, AngularJS, CSS, Bootstrap.
Consuming Api via Ajax call in the Javascript. We use a CMS and convert the HTML to custom asset in cold fusion(just change the .html to .cfm). That custom asset is in Production server.

Now the Api is deployed in the dev server and UI code files deployed in Production server which is trying to access the Api from dev server.


Please give me some solution, how can I fix this issue.

What I have tried:

Dev Api url tried in Production server browser, local browser, and dev server browser works every where. But when I run the production deployed application I can see the UI but no Api data in the fields.
Posted
Updated 16-May-16 17:42pm
Comments
santosh.yadav198613 16-May-16 10:05am    
It can be done by adding custom headers, if you are using MVC you can add your own attribute to avoid this.
proudwarrior 16-May-16 23:39pm    
Thanks,I fixed the issue.

1 solution

Added Enable CORS configuration in WebApiConfig
Under Register I have added this code.
var cors = new EnableCorsAttribute("*", "*", "*");
            config.EnableCors(cors);
 
Share this answer
 

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