Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7973449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:06:27+00:00 2026-06-04T08:06:27+00:00

So here is the code using S.DS.P to get all users very quickly in

  • 0

So here is the code using S.DS.P to get all users very quickly in pages of 500 at a time..

public List<AllAdStudentsCV> GetUsersDistinguishedNamePagedResults( string domain, string distinguishedName )
        {
            try
            {
                NetworkCredential credentials               = new NetworkCredential( ConfigurationManager.AppSettings["AD_User"], ConfigurationManager.AppSettings["AD_Pass"] );
                LdapDirectoryIdentifier directoryIdentifier = new LdapDirectoryIdentifier( domain + ":389" );

                List<AllAdStudentsCV> users = new List<AllAdStudentsCV>();

                using (LdapConnection connection = new LdapConnection(directoryIdentifier, credentials))
                {
                    string filter = "(&(objectClass=user)(objectCategory=person))";
                    string baseDN = ConfigurationManager.AppSettings["AD_DistinguishedName"];

                    string[] attribArray = {"name", "sAMAccountName", "objectGUID", "telexNumber", "HomePhone"};

                    List<SearchResultEntry> srList = PerformPagedSearch(connection, baseDN, filter, attribArray);

                    if (srList.Count == 0) return null;

                    foreach (SearchResultEntry entry in srList)
                    {
                        <...snip a bunch of code to filter out bad users by CN...>

                                users.Add( user );
                            }
                            catch ( Exception ex )
                            {
                                throw;
                            }
                        }
                    }
                }
                return users;
            }
            catch ( Exception ex )
            {
                throw;
            }
        }

private List<SearchResultEntry> PerformPagedSearch( LdapConnection connection, string baseDN, string filter, string[] attribs )
        {
            List<SearchResultEntry> results = new List<SearchResultEntry>();

            SearchRequest request = new SearchRequest(
                baseDN,
                filter,
                System.DirectoryServices.Protocols.SearchScope.Subtree,
                attribs
                );

            PageResultRequestControl prc = new PageResultRequestControl(500);

            //add the paging control
            request.Controls.Add(prc);
            int pages = 0;
            while (true)
            {
                pages++;
                SearchResponse response = connection.SendRequest(request) as SearchResponse;

                //find the returned page response control
                foreach (DirectoryControl control in response.Controls)
                {
                    if (control is PageResultResponseControl)
                    {
                        //update the cookie for next set
                        prc.Cookie = ((PageResultResponseControl) control).Cookie;
                        break;
                    }
                }

                //add them to our collection
                foreach (SearchResultEntry sre in response.Entries)
                {
                    results.Add(sre);
                }

                //our exit condition is when our cookie is empty
                if ( prc.Cookie.Length == 0 )
                {
                    Trace.WriteLine( "Warning GetAllAdSdsp exiting in paged search wtih cookie = zero and page count =" + pages + " and user count = " + results.Count );
                    break;
                }
            }
            return results;
        }

It works perfectly on DEV and on Prod, but suddenly stopped working on the QA webserver when it talks to the QA AD server. it only returnes one page and then stops.
If I point DEV to the QA AD server it works correctly…

It was working before Feb 2012, last time I tested in QA, and definitely was broken in place by March 7, 2012

Can anyone think of anything that would cause this behavior? perhaps a windows update? I’ve had one jack this product up before…

I’m reasonably convinced that it’s not the code or the configuration…as it works on so many other combinations… it’s netowrk/securiyt/os related.. but I can’t figure out what changed.

Any Help is appreicated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:06:28+00:00Added an answer on June 4, 2026 at 8:06 am

    Had the exact same issue where no pages were returned after the first one.

    Here is what I found to fix the problem:

    PageResultRequestControl pageRequestControl = new PageResultRequestControl(500);
    
    SearchOptionsControl soc = new SearchOptionsControl(System.DirectoryServices.Protocols.SearchOption.DomainScope);
    
    request.Controls.Add(pageRequestControl);
    request.Controls.Add(soc);
    

    No idea what the SearchOptionsControl does, but since I added this, AD returns all the expected objects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the code I'm using to make a custom AlertDialog. public void onButtonClicked(View v)
here is a code : using System; using Nemerle.Collections; using Nemerle.Text; //using Nemerle.Utility; using
Here is the my python code using BeautifulSoup. The main issue is with the
Having this code: using (BinaryWriter writer = new BinaryWriter(File.Open(ProjectPath, FileMode.Create))) { //save something here
Here's the code I'm using: // create a request HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
here is my code i am using to fetch mysql result from 4 different
Here is my code i am using for custom search, <div id=cse-search-form style=width: 100%;>Loading</div>
I'm using some code from here to determine when determining when the last finger
here is code for regular expression matching #include<iostream> #include<stdio.h> #include<string.h> using namespace std; int
Im using Doctrine and i dont quite understand this code here: $this->hasColumn('id', 'integer', 8,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.