在服务器端,Silverlight,DBC等的SharePoint Intranet上处理跨域的最佳方式 [英] Best way to handle Cross Domain on SharePoint Intranet w/o server side, silverlight, DBC etc
问题描述
我在Microsoft内部SharePoint网站上工作,我需要从跨网域SharePoint网站中提取列表数据。
I'm working on a Microsoft internal SharePoint site, and I need to pull in List data from a cross domain SharePoint site.
我不想使用Silverlight,因为各种原因,并且现在不可能实现业务数据连接。
I don't want to use Silverlight, for various reasons, and Business Data Connectivity is not possible right now.
有没有简单的方法使用JavaScript或类似的东西来完成这个? p>
Is there a simple way to use JavaScript or something like it to accomplish this?
推荐答案
简单?不完全是。根据您的要求,特别是 w / o服务器端,这是不可能的。
"Simple?" Not exactly. Given your requirements, particularly "w/o server side," this isn't possible.
您有几个启用跨网域请求的选项。
However, if you can forego that requirement, you have a few options for enabling cross-domain requests.
有体面支持,用于跨源资源共享 XMLHttpRequest
和Microsoft的 XDomainRequest
。但是,这将要求远程服务器在响应中包含适当的标头,以允许您的源/域提出请求。
There's decent support for Cross-Origin Resource Sharing for XMLHttpRequest
and Microsoft's XDomainRequest
. Though, this will require that the remote server include the proper headers in the response to allow your origin/domain to make the request.
<% Response.AddHeader("Access-Control-Allow-Origin", "*") %>
JSONP
a href =http://en.wikipedia.org/wiki/JSONP> JSONP ,它会在< script>
中加载资源 callback
参数与全局函数的名称。由于JSON基于JavaScript文字,因此不会有相同的浏览器支持问题,但是远程服务器必须知道如何构造输出,并且限于 GET
请求。
JSONP
A common option is JSONP, which loads the resource in a <script>
with a callback
parameter with the name of a global function. Since JSON is based on JavaScript literals, this won't have the same browser-support issues, but the remote server will have to know how to construct the output and it's limited to GET
requests.
// <script src="http://other.dom/resource?callback=loadResource"></script>
loadResource( [ {"id": 1, "name": "foo"}, {"id": 2, "name": "bar"} ] );
服务器端代理
您请求的远程服务器无法(或不会)调整为支持跨域请求,您几乎可以在服务器上创建服务器端代理。
Server-side Proxy
If the remote server you're requesting from can't (or won't) be adjusted to support cross-domain requests, you're pretty much left with making a Server-Side Proxy on your server.
一般模式在 AjaxPatters.org 中介绍,并且可以找到许多.NET实现,包括 John Chapman的和跨域Proxy 专案。
The general pattern is described at AjaxPatters.org and a number of .NET implementations can be found, including John Chapman's and the Cross-Domain Proxy project.
这篇关于在服务器端,Silverlight,DBC等的SharePoint Intranet上处理跨域的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!