Directory Programming .NET

Active Directory and ADAM programming support for .NET developers
Welcome to Directory Programming .NET Sign in | Join | Help
in Search

SearchRequest in root DN with Subtree scope

Last post 02-08-2010, 8:02 AM by slemieux. 2 replies.
Sort Posts: Previous Next
  •  02-05-2010, 3:05 PM 7799

    SearchRequest in root DN with Subtree scope

    Hi!

    I want to implement an AD search in C#  using the LdapConnection and SearchRequest/SearchResponse objects.

    As I don't know other information about the search object than its account name, I want to start my search in the root DN by doing this:

    SearchRequest searchRequest = new SearchRequest(null, ldapSearchFilter, SearchScope.Subtree,attributesToReturn);

    This doesn't work.

    I think it would work if i could provide the real root DN of the server. Is there a way to get it from the host name programmatically?

    Thanks!

  •  02-06-2010, 1:47 PM 7802 in reply to 7799

    Re: SearchRequest in root DN with Subtree scope

    Try changing the first parameter to an empty string instead of NULL.

    If you've got a disjoint namesspace and only want to search from the root, your first call should be to the RootDSE to get the rootDomainNamingContext. This is necessary since a global catalog can be any server in the forest so if you don't define, your default connection may be to a GC in a child domain and your default search may start in the child domain's context.

    SearchRequest("", "objectClass=*", SearchScope.Base, attributes)

    The your subsequent subtree searches can start at the defined rootDomainNamingContext.

  •  02-08-2010, 8:02 AM 7804 in reply to 7802

    Re: SearchRequest in root DN with Subtree scope

    That's exactly what I was looking for. Thanks!
View as RSS news feed in XML