0

I have a application hosted with domain www.abc.com .This is actually WebApi application . I want to build a separate UI application using asp.net mvc, and its domain is www.xyz.com. The UI application consuming Angular,HTML5 and other Web technologies.Here i really need to perform GET,PUT,POST,DELETE against www.abc.com. unfortunately the limitation of jsonp , i like to choose CORS (HTML5 Cors), but i can't pass json object to CORS calls . what are the best possible best approach to call cross domain calls (GET,PUT,POST,DELETE) using angularJs with my problem scenario . What should i change in IIS to handle CORS request.

1
  • did you find my answer useful. please accept and upvote if so Commented May 11, 2014 at 12:32

2 Answers 2

2

add below web.config in webapi

<system.webServer>
    <httpProtocol>
        <customHeaders>               
            <add name="Access-Control-Allow-Origin" value="*" />
        </customHeaders>
    </httpProtocol>
</system.webServer>

and in angular, set below config options for $http

header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Origin: http://url.com:8080");
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization");

also check: this link

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

1 Comment

Quick note to say that the domain name was changed. If you want to check the link mentioned above, see samurails.com/tutorial/cors-with-angular-js-and-sinatra
0

To enable cross domain ajax calls you can place crossdomain.config in asp.net web api root folder when published with following contents.

<?xml version="1.0"?>
<cross-domain-policy>
<allow-access-from domain="*"/>
</cross-domain-policy>

2 Comments

The OP asked about CORS, not JSONP. Your solution will only work for GET requests anyway.
@Ray Nicholus I update my answer. on other hand, I implemented a web services using asp.net web api for mobile client for which I need to manage/enable cross domain ajax calls. So I place the crossdomain.config with contents above in application root folder while publishing, and it enables us to access the web api end points. Therefore, I don't understand why you down rated it. Also, it should work fine for both get and post. You are ought to explain with reference where I am wrong with my answer. So that I can correct myself.

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.