从应用程序访问时拒绝来自位于不同Web应用程序中的Web列出项目
问题描述:
我创建了一个SharePoint托管应用程序并安装在位于WebApplication1上的站点上。此应用程序尝试从位于Webapplication2上的站点中的列表中获取列表项。我尝试过不同的解决方案(REST和csom),但它会生成
访问被拒绝。以下是我的代码。
我在清单文件中添加了一个RemoteEndPoint,它指向包含列表的网页。
I have create a SharePoint Hosted App and installed on a Site which is located on WebApplication1. This app tries to get list items from a list in a site which is located on Webapplication2. I have tried different solutions (REST and csom) but it generates
access denied. Following is my code.
I have added a RemoteEndPoint to the manifest file which points to the web that contains the list.
var appweburl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"));
var blogWebUrl = "https://webapplication2.com/personal/userName/Blog";
var context1 = new SP.ClientContext(appweburl);
var factory = new SP.ProxyWebRequestExecutorFactory(appweburl);
context1.set_webRequestExecutorFactory(factory);
var blogWebContext = new SP.AppContextSite(context1, blogWebUrl);
var blogWeb = blogWebContext.get_web();
var list = blogWeb.get_lists().getByTitle("Posts");
var camlString =
"<View><ViewFields>" +
"<FieldRef Name='Title' />" +
"<FieldRef Name='Body' />" +
"</ViewFields></View>";
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(camlString);
var allPosts = list.getItems(camlQuery);
context1.load(allPosts, "Include(Title, Body)");
context1.executeQueryAsync(
Function.createDelegate(this, function (sender, args) {
alert("okkkkk");
}),
Function.createDelegate(this, function (sender, args) {
alert('failed: ' + args.get_message());
})
);
答
跨域JS库可以从同一租户内的域中获取数据。对于现场SharePoint安装,同一Web应用程序中的方法。
The cross-domain JS library can get data from domains within the same tenancy. In the case of an onsite SharePoint installation, the means within the same web application.