validation网络凭据以访问客户端对象模型上的SharePoint站点

我正在使用小应用程序,这需要将所有用户都带到给定站点的所有组中。 我有两个网站; SharePoint 2010在线运行和SharePoint 2013在线运行。 我收到凭据错误…

{"The remote server returned an error: (401) Unauthorized."} 

码。

  public class Program { static void Main(string[] args) { string _siteURL = "https://intranet.co.uk"; NetworkCredential _myCredentials = new NetworkCredential("user", "password", "https://intranet"); ClientContext _clientContext = new ClientContext(_siteURL); _clientContext.Credentials = _myCredentials; Web _MyWebSite = _clientContext.Web; GroupCollection _GroupCollection = _MyWebSite.SiteGroups; _clientContext.Load(_GroupCollection); _clientContext.Load(_GroupCollection, groups => groups.Include(group => group.Users) ); _clientContext.ExecuteQuery(); foreach (Group _group in _GroupCollection) { Console.WriteLine("Group Id " + _group.Id + " Group Title " + _group.Title); UserCollection _userCollection = _group.Users; foreach (User _user in _userCollection) { Console.WriteLine("Group ID: {0} Group Title: {1} User: {2} Login Name: {3}", _user.Title, _user.LoginName); } Console.WriteLine("\n......................................."); } Console.Read(); } 

您的凭据是错误的,特别是您的域名。

 NetworkCredential _myCredentials = new NetworkCredential("user", "password", "https://intranet"); 

您的useraccount被指定为domain\username ,我怀疑您的域名将是https://intranet ,而不是companyname 。 如果您不确定,请询问您的Exchange管理员。

您正在寻找的是类似于此的东西:

 NetworkCredential _myCredentials = new NetworkCredential("user", "password", "companydomain"); //OR NetworkCredential _myCredentials = new NetworkCredential(@"companydomain\user", "password");