Quantcast
Channel: Directory Services forum
Viewing all articles
Browse latest Browse all 31638

System.DirectoryServices.Protocols.SearchRequest Ldap Query Execution Problem

$
0
0

Hi,

     I am using DirectorySearcher class to query the active directory. It gives all the records in a single page (more than 5000). I want to get 100 records per page. So I moved to SearchRequest class. Using SearchRequest class I can get 100 records per page. But for particular query it is not working. I want to get all the users with their"samaccountname or displayname starts with 'a'" works fine. Then I want to get all the users with their"samaccountname and displayname starts with 'a'", this it is not working. I can guess the reason, some of the users starts their samaccountname with a not having any displayname. Any workaround for this issue? Please guide me

Please refer the following code

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


Viewing all articles
Browse latest Browse all 31638

Latest Images

Trending Articles





Latest Images