简体   繁体   English

System.DirectoryServices.Protocol搜索问题

[英]System.DirectoryServices.Protocol search question

I'm trying to re write a search from System.DirectoryServices to System.DirectoryServices.Protocol 我试图将搜索从System.DirectoryServices重新写到System.DirectoryServices.Protocol

In S.DS I get all the requested attributes back, but in S.DS.P, I don't get the GUID, or the HomePhone... 在S.DS中,我获得了所有请求的属性,但是在S.DS.P中,我没有获得GUID或HomePhone ...

The rest of it works for one user. 其余的仅适用于一个用户。

Any Ideas? 有任何想法吗?

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;
            }
        }

Also, if I want to fetch EVERY user in AD, so I can synch data with my SQL DB, how do I do that, I Kept getting max size exceeded, errors. 另外,如果我想获取AD中的每个用户,以便可以与SQL DB同步数据,该怎么做,我一直无法获得最大大小,因此会出错。 I set the size to maxInt32... is there an "ignore size" option? 我将大小设置为maxInt32 ...是否有“忽略大小”选项?

Thanks, 谢谢,

Eric- 埃里克

I think that the standard way is to use System.DirectoryServices, not System.DirectoryServices.Protocol. 我认为标准方法是使用System.DirectoryServices,而不是System.DirectoryServices.Protocol。 Why do you want to user the later ? 为什么要稍后使用?

Concerning your second question about the error message "max sized exceeded", it may be because you try to fetch too many entries at once. 关于错误消息“超出最大大小”的第二个问题,可能是因为您尝试一次获取太多条目。
Active Directory limits the number of objects returned by query, in order to not overload the directory (the limit is something like 1000 objects). Active Directory限制了查询返回的对象数,以便不使目录超载(该限制类似于1000个对象)。 The standard way to fetch all the users is using paging searchs. 获取所有用户的标准方法是使用分页搜索。

The algorithm is like this: 算法是这样的:

  1. You construct the query that will fetch all the users 您构造将获取所有用户的查询
  2. You specify a specific control (Paged Result Control) in this query indicating that this is a paged search, with 500 users per page 您在此查询中指定一个特定的控件(分页结果控件),指示这是一个分页搜索,每页有500个用户
  3. You launch the query, fetch the first page and parse the first 500 entries in that page 您启动查询,获取第一页并解析该页中的前500个条目
  4. You ask AD for the next page, parse the next 500 entries 您要求广告进入下一页,解析接下来的500个条目
  5. Repeat until there are no pages left 重复直到没有剩余页面

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.DirectoryServices.Protocol移动用户问题 - System.DirectoryServices.Protocol move user question System.DirectoryServices.Protocol 从组中添加/删除用户 - System.DirectoryServices.Protocol add/remove user from group 如何在C#中的System.DirectoryServices.Protocol中获取嵌套组(子组) - How to get nested groups (subgroups) in System.DirectoryServices.Protocol in c# 如何使用System.DirectoryServices.Protocol验证用户名/密码? - How would I validate a Username/Password using System.DirectoryServices.Protocol? 如何使用 System.DirectoryServices.AccountManagement 在多个域中搜索? - How to search in multiple domains using System.DirectoryServices.AccountManagement? 使用System.DirectoryServices.Protocols在Active Directory上执行分页搜索 - Performing paginated search on Active Directory using System.DirectoryServices.Protocols System.DirectoryServices很慢? - System.DirectoryServices is slow? System.DirectoryServices很慢 - System.DirectoryServices is slow 试图在System.DirectoryServices.AccountManagement中搜索以找到具有寻呼机字段的AD用户包含字符串 - trying to search in System.DirectoryServices.AccountManagement to find AD user with pager field contains a string 如何使用 System.DirectoryServices 在 Apache Directory Studio 上搜索 LDAP 用户数据? - How to do a search of LDAP user data on Apache Directory Studio with System.DirectoryServices?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM