我需要检索用户使用客户端对象模型有权访问的子网站。
这是我得到的:
NetworkCredential credential = new NetworkCredential(user, pwd, domain);
ClientContext clientContext = new ClientContext(string.Format("http://{0}:{1}/", server, port));
clientContext.Credentials = credential;
Web oWebsite = clientContext.Web;
clientContext.Load(oWebsite, website => website.Webs, website => website.Title);
clientContext.ExecuteQuery();
infos = new List<Infos>();
Infos info = null;
for (int i = 0; i != oWebsite.Webs.Count; i++)
{
info = new Infos();
info.SubSite = oWebsite.Webs[i].Title;
info.UrlSubSite = oWebsite.Webs[i].ServerRelativeUrl;
ListCollection lists = oWebsite.Webs[i].Lists;
clientContext.Load(lists);
clientContext.ExecuteQuery();
foreach (var list in lists)
{
Lists myList = new Lists();
myList.Title = list.Title;
info.Listas.Add(myList);
}
infos.Add(info);
}
var query = from Infos i in infos
select i.SubSite;
return query.ToList();
}
catch(Exception ex)
{
throw ex;
}
return null;
}
=====
使用此代码,我收到 403 禁止错误。我的客户端用户在根站点(我在 ClientContext 构造函数中使用)上没有访问权限。但他在一些子网站下。我需要使用客户端对象模型获取他有权访问的子网站(只需列出所有子网站)。
还有别的办法吗?
ClientContext clientContext =
new ClientContext(string.Format("http://{0}:{1}/",
server,
port));
WebCollection webs = clientContext.Web.GetSubwebsForCurrentUser(null);