1
我试图使用CSOM从根站点访问数据,然后循环遍历子站点以获取存储在其列表中的文件。当我去创建ClientContext时,它可以很好地处理根URL,但是当我使用其中一个子网站的URL时,当我点击ExecuteQuery()时,会得到一个401。在子网站上查询的SharePoint 2010 CSOM-401
using (var clientContext = new ClientContext(rootURL))
{
Console.WriteLine("Establishing connection...");
var userName = System.Configuration.ConfigurationManager.AppSettings["userName"];
var domain = System.Configuration.ConfigurationManager.AppSettings["domain"];
var password = System.Configuration.ConfigurationManager.AppSettings["pwd"];
var credentials = new NetworkCredential(userName, password, domain);
clientContext.Credentials = credentials;
_clientContext = clientContext;
var spContext2 = new SharePointClientDataContext(clientContext);
ClientContext newContext = new ClientContext(subsiteURL);
var allLists = newContext.Web.Lists;
newContext.Load(allLists);
newContext.ExecuteQuery();
try
{
...
代码在newContext.ExecuteQuery()失败。任何想法为什么我会在子网站上遇到401,而不是根级?
还值得注意的是,这样做本地工作,但我目前正试图从我的主机操作系统运行此从我的虚拟机访问文件。
您可否详细说明“将凭据设置为新的客户端上下文”? –
查看我的更新回答 – Matt
就是这样,@Matt!谢谢! – awh112