-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!

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

going to lunch will try this when i get back.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.