Inx
Inx

Reputation: 2384

Breezejs, crossdomain

I have a minor...or maybe major.. problem regarding breezejs.. My current setup is that I have two projects.. one web-api project that hosts the breeze-api.. and another project which hosts the client-application thats supposed to consume the api.. This will give me two different ports which the api and the client runs on..

So my question is... is there any way to get breeze to work on cross-domains?.. or is breeze only built to be used inside its own domain?

Thanks in advance!

Upvotes: 2

Views: 485

Answers (2)

konzo
konzo

Reputation: 2093

The Ward'd solution is very correct, am just adding a more direct solution.

Now do this install the package.

Microsoft.AspNet.WebApi.Cors

then add this to web.config

<system.webServer>
<httpProtocol>
<customHeaders>
  <add name="Access-Control-Allow-Origin" value="*"/>
  <add name="Access-Control-Allow-Headers" value="Content-Type"/>
  <add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS"/>
</customHeaders>
</httpProtocol>
</system.webServer>

Change "Access-Control-Allow-Origin" to your other site * is a security risk as it allows all am using it for development

Then add this altribrute to the resource yo wish to be accesible

[EnableCors(origins: "*", headers: "*", methods: "*")]

Again change the origin here too remember no backslash at the end of the url.

Upvotes: 0

Ward
Ward

Reputation: 17863

No problem going cross domain.

Ok there is a problem but it is NOT a Breeze problem. You are wrestling with the browser's "Same Origin Policy" that plagues us all.

You can circumvent it. Only question is how you want to go about it. And THAT question begins with "what browsers will you be supporting." If IE10+ and latest Chrome and FF, you should go CORS. If older browsers and Opera ... you'll have to fight the JSONP battles.

Please advise.

Nudge: Guess which one I prefer? There is already a CORS sample in Breeze ... it's the Todo sample which you get with the downloads. It's not documented yet but it's in there waiting for you.

Upvotes: 3

Related Questions