-1

I'm trying to grab JSON data from a Web API we've built on another server. Ideally i'd like to call the URL to grab the JSON from the Web API directly from an Angular Factory, but I get the cross-domain error.

Right now my Factory calls the ASP Controller and the ASP Controller grabs the JSON from the Web API just fine.. but I find it an extra unnecessary step if I could just grab the data from my Factory directly.

Here are some of the guides I've tried that I can't get to work:

AngularJS + ASP.NET Web API Cross-Domain Issue

http://blogs.msmvps.com/deborahk/angular-front-to-back-with-web-api-problem-solver/

help please!

Community
  • 1
  • 1
user1189352
  • 3,628
  • 12
  • 50
  • 90

1 Answers1

0

You need to create a clientaccesspolicy.xml file in the root of your application:

<?xml version="1.0" encoding="utf-8" ?>
<access-policy>
  <cross-domain-access>
    <policy>
      <allow-from http-request-headers="something-to-identify-your-app">
        <domain uri="*" />
      </allow-from>
      <grant-to>
        <resource path="/" include-subpaths="true"/>
      </grant-to>
    </policy>
  </cross-domain-access>
</access-policy>

Then make sure you include that request header in your calls to the service.

Robharrisaz
  • 313
  • 1
  • 11