How to handle cross-domain web service calls from JS in Orchard CMS

依然范特西╮ 提交于 2019-12-01 05:10:30
Piotr Szmyd

Cross-domain calls from within client-side code are a no-no in all major browsers. You can either

  1. Use CORS, ie. set Access-Control-Allow-Origin header to http://your-caller-domain.com in the web service response to allow requests originating from your website domain
  2. Use JSONP technique
  3. Create a custom proxy API within your application (using plain ASP.NET MVC controller or a WebAPI one) that will perform the call on server side using WebClient class and return the response to you.

Options are ordered from best to worst. CORS is supported by most browsers, except IE8/9 (which have partial support via XDomainRequest) and older. There are workarounds for this though.

Note that first two involve changes on the web-service side - if you can't do it, option 3. is the only one left.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!