如何处理来自JS在果园CMS跨域Web服务调用 [英] How to handle cross-domain web service calls from JS in Orchard CMS

查看:215
本文介绍了如何处理来自JS在果园CMS跨域Web服务调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从HTML控件中调用Web服务跨域。这似乎并没有工作。它同一个域下的伟大的工作。我想在乌节可用于登录到我的另一个域软件创建一个登录页面。 Web服务是验证用户凭据并返回一个布尔值,然后将生成的用户认证。

I am trying to call a web service cross domain from within an HTML widget. This does not seem to work. It worked great under the same domain. I am trying to create a log in page within Orchard that could be used to log in to my software on another domain. The web service is validating the user credentials and returning a boolean which then would generate the users authentication.

我看了,我可以使用一个HTTP处理程序或其它Web服务(在果园边)来调用Web服务上的其他领域,但我不熟悉不够用MVC或果园做到这一点。如何添加其中一个到我的果园Web应用程序?

I read that I could use an HTTP Handler or another web service (on the Orchard side) to call the web service on the other domain, but I'm not familiar enough with MVC or Orchard to do this. How can I add one of these to my Orchard web application?

推荐答案

跨域从内部客户端code调用是一个没有没有在所有的主流浏览器。 您可以

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

  1. 使用 CORS ,即。设置访问控制 - 允许 - 原产地在网页标题 http://your-caller-domain.com 服务响应,允许请求从您的网站域名原
  2. 使用 JSONP 技术
  3. 创建一个自定义的代理API 您的应用程序中(使用普通的 ASP.NET MVC控制器或<一href="http://www.west-wind.com/weblog/posts/2012/Aug/21/An-Introduction-to-ASPNET-Web-API">WebAPI一个)会使用 Web客户端类在服务器端执行的调用和返回响应你。
  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.

选项以最佳责令最差。 CORS是大多数浏览器都支持,但IE8 / 9(这必须通过 XDomainRequest 部分支持)和老年人。有解决方法这虽然。

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.

需要注意的是前两种方法的改变在网络服务端 - 如果你不能做到这一点,选项3,是一个只剩

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

这篇关于如何处理来自JS在果园CMS跨域Web服务调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆