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

2023-12-04

我正在开发小型应用程序,需要将给定网站的所有组中的所有用户都吸引过来。我有两个网站; SharePoint 2010 在本地运行,SharePoint 2013 在线运行。我收到凭据错误...

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

code.

 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");

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

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

NetworkCredential _myCredentials = new NetworkCredential("user", "password", "companydomain");
//OR
NetworkCredential _myCredentials = new NetworkCredential(@"companydomain\user", "password");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

验证网络凭据以访问客户端对象模型上的 SharePoint 网站 的相关文章

随机推荐