验证网络凭据以访问客户端对象模型上的SharePoint网站 [英] Authenticate network credential to access SharePoint site on client object model
问题描述
我正在开发小型应用程序,这要求将所有用户带入给定站点的所有组中.我有两个站点;先决条件上运行的SharePoint 2010和Online上运行的SharePoint 2013.我收到凭证错误...
I am working to small app, that is require to bring all users in all groups of given site. I have two sites; SharePoint 2010 running on premisses and SharePoint 2013 online. I am getting credential error...
{"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();
}
推荐答案
您的凭据错误,尤其是您的域错误.
Your credentials are wrong, espacially your domain.
NetworkCredential _myCredentials = new NetworkCredential("user", "password", "https://intranet");
您的用户帐户被指定为 domain \ username
,我怀疑您的域名将是 https://intranet
,而不是 companyname
.如果不确定,请咨询您的Exchange管理员.
Your useraccount is specified as domain\username
and I doubt your domainname would be https://intranet
, but rather companyname
. If you are not sure, ask your Exchange administrator.
您正在寻找的东西与此类似:
What you are looking for is something analog to this:
NetworkCredential _myCredentials = new NetworkCredential("user", "password", "companydomain");
//OR
NetworkCredential _myCredentials = new NetworkCredential(@"companydomain\user", "password");
这篇关于验证网络凭据以访问客户端对象模型上的SharePoint网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!