协议搜索问题

本文关键字:问题 搜索 协议 | 更新日期: 2023-09-27 18:07:21

我正在尝试从系统重写搜索。目录服务到System.DirectoryServices.Protocol

在S.DS中,我得到所有请求的属性,但在S.DS中。P,我没有GUID,或者HomePhone…

其余部分只适用于一个用户。

任何想法?

public static List<AllAdStudentsCV> GetUsersDistinguishedName( string domain, string distinguishedName )
        {
            try
            {
                NetworkCredential credentials               = new NetworkCredential( ConfigurationManager.AppSettings[ "AD_User" ], ConfigurationManager.AppSettings[ "AD_Pass" ] ); 
                LdapDirectoryIdentifier directoryIdentifier = new LdapDirectoryIdentifier( domain+":389" ); 
                using ( LdapConnection connection           = new LdapConnection( directoryIdentifier, credentials ) )
                {
                    SearchRequest searchRequest = new SearchRequest( );
                    searchRequest.DistinguishedName = distinguishedName;
                    searchRequest.Filter = "(&(objectCategory=person)(objectClass=user)(sn=Afcan))";//"(&(objectClass=user))";
                    searchRequest.Scope = SearchScope.Subtree;
                    searchRequest.Attributes.Add("name");
                    searchRequest.Attributes.Add("sAMAccountName");
                    searchRequest.Attributes.Add("uid");
                    searchRequest.Attributes.Add("telexNumber"); // studId
                    searchRequest.Attributes.Add("HomePhone"); //ctrId
                    searchRequest.SizeLimit = Int32.MaxValue;
                    searchRequest.TimeLimit = new TimeSpan(0, 0, 45, 0);// 45 min - EWB
                    SearchResponse searchResponse = connection.SendRequest(searchRequest) as SearchResponse;
                    if (searchResponse == null) return null;
                    List<AllAdStudentsCV> users = new List<AllAdStudentsCV>();
                    foreach (SearchResultEntry entry in searchResponse.Entries)
                    {
                        AllAdStudentsCV user = new AllAdStudentsCV();
                        user.Active = "Y";
                        user.CenterName = "";
                        user.StudId = GetstringAttributeValue(entry.Attributes, "telexNumber");
                        user.CtrId = GetstringAttributeValue(entry.Attributes, "HomePhone");
                        user.Guid = GetstringAttributeValue(entry.Attributes, "uid");
                        user.Username = GetstringAttributeValue(entry.Attributes, "sAMAccountName");
                        users.Add(user);
                    }
                    return users;
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }

另外,如果我想在AD中获取每个用户,所以我可以与我的SQL数据库同步数据,我该如何做到这一点,我一直在获得最大尺寸超过,错误。我将大小设置为maxxint32…是否有"忽略大小"选项?

谢谢,

埃里克-

协议搜索问题

我认为标准的方法是使用System。DirectoryServices,而不是System.DirectoryServices.Protocol。为什么要使用后者?

关于你的第二个问题关于错误消息"max size exceeded",这可能是因为你试图一次获取太多的条目。
为了不使目录过载,Active Directory限制查询返回的对象的数量(限制大约是1000个对象)。获取所有用户的标准方法是使用分页搜索。

算法如下:

  1. 您构建将获取所有用户的查询
  2. 您在此查询中指定一个特定的控件(分页结果控件),表明这是分页搜索,每页500个用户
  3. 您启动查询,获取第一个页面并解析其中的前500个条目这个页面
  4. 向AD请求下一页,解析后面的500个条目
  5. 重复,直到没有页面剩余