在主机站点上访问应用程序Web中的列表生成拒绝访问
-
10-12-2019 - |
题
我正在尝试通过使用CSOM(JavaScript)从SharePoint托管应用程序获取位于主机站点上的列表的标题。我在清单文件上添加了权限,并选择了列表,但仍然在ExecuteQueryAsync上拒绝访问。这是我的代码:
hostweburl = decodeURIComponent(getQueryStringParameter('SPHostUrl'));
var hostcontext = new SP.ClientContext(hostweburl);
var oList = hostcontext.get_web().get_lists().getByTitle('SliderList');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(' som query to get proper items')
this.collListItem = oList.getItems(camlQuery);
hostcontext.load(collListItem);
hostcontext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
.
它不会转到OnquerySuccess或OnqueryFailed,它可以在SP_ClientRuntimeContext $ executequeryAsync,sp.runtime.debug.js,行3103 上访问访问权限
解决方案
实际上需要为 app web 和 sp.appcontextsite for host web生成sp.clientcontext。要在主机Web中获取列表,请尝试以下内容:
.// Get the ClientContext for the app web
clientContext = new SP.ClientContext.get_current();
// Use the host web URL to get a parent context - this allows us to get data from the parent
hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
parentCtx = new SP.AppContextSite(clientContext, hostweburl);
parentWeb = parentCtx.get_web();
parentList = parentWeb.get_lists().getByTitle("SliderList");