首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >System.DirectoryServices.Protocols.SearchRequest Ldap查询执行问题

System.DirectoryServices.Protocols.SearchRequest Ldap查询执行问题
EN

Stack Overflow用户
提问于 2012-02-09 15:52:37
回答 1查看 964关注 0票数 2

我正在使用DirectorySearcher类来查询活动目录。它将所有记录放在一个页面中(超过5000条)。我希望每页有100条记录。所以我转到了SearchRequest班。使用SearchRequest类,我可以获得每页100条记录。但是对于特定的查询,它不起作用。我想让所有用户的"samaccountname或displayname以‘a’开头“都能正常工作。然后我想获取所有用户的"samaccountname和displayname以‘a’开头“,这是不起作用的。我可以猜到原因,一些用户在他们的samaccountname开头没有任何displayname。是否有解决此问题的方法?请给我指引

请参考以下代码

代码语言:javascript
复制
        //This query works fine
        //string filter = "(&(objectCategory=person)(objectClass=user)(!sAMAccountType=805306370)(|(samaccountname=a*)(displayname=a*)))";


        /* Not works */
        string filter = "(&(objectCategory=person)(objectClass=user)(!sAMAccountType=805306370)(&(samaccountname=a*)(displayname=a*)))";
        LdapConnection connection = new LdapConnection(serverName);
        string[] attribs = { "samaccountname", "displayname" };

        // create a SearchRequest object
        SearchRequest searchRequest = new SearchRequest
                                                (scope,
                                                 filter,
                                                 System.DirectoryServices.Protocols.SearchScope.Subtree,
                                                 attribs);

        SortRequestControl sortRequest = new SortRequestControl("samaccountname", false);
        searchRequest.Controls.Add(sortRequest);

        VlvRequestControl vlvRequest =
            new VlvRequestControl(0, numEntries, offsetVal);
        searchRequest.Controls.Add(vlvRequest);

        SearchResponse searchResponse =
            (SearchResponse)connection.SendRequest(searchRequest);

        if (searchResponse.Controls.Length != 2 ||
            !(searchResponse.Controls[0] is SortResponseControl))
        {
            Console.WriteLine("The server does not support VLV");
            return null;
        }
EN

回答 1

Stack Overflow用户

发布于 2012-02-10 10:33:47

您确实想在Active Directory中使用displayName吗?也许fullName或CN会是更准确的选择。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9207170

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档