Discussion:
How to use 'Base Dn' in DirectorySearcher Filter?
(too old to reply)
Dave
2005-11-30 18:07:03 UTC
Permalink
I'm using ldp.exe to connect to our global catalog in order to test my ad
search:

Base Dn: dc=abc,dc=mycompany,dc=com
Filter: (&(sAMAccountName=jsmith))
Scope: SubTree

Works fine, but how do I incorporate the 'Base Dn' attribute in the
DirectorySearcher below?

Here's my code:

DirectoryEntry entry = new DirectoryEntry("GC://mycompany.com", user, pass);
DirectorySearcher search = new DirectorySearcher(entry);

search.Filter = "(&(sAMAccountName=jsmith))";;
search.SearchScope = SearchScope.Subtree;
SearchResult result = search.FindOne();

Where does the Base Dn fit above? Thanks
Joe Kaplan (MVP - ADSI)
2005-11-30 19:00:18 UTC
Permalink
The DirectorySearcher gets both the Base DN and the credentials used for
binding from the DirectoryEntry object that is set in the SearchRoot
property.

In your code below, to set the base DN, add that DN to the ADsPath in the
first argument of your DirectoryEntry constructor:

DirectoryEntry entry = new DirectoryEntry
("GC://mycompany.com/dc=abc,dc=mycompany,dc=com", user, pass,
AuthenticationTypes.Secure);

The ADsPath is essentially composed of the scheme, the server information
(which is optional with AD sometimes) and the object name, which with LDAP
(or GC), is the DN of the object.

HTH,

Joe K.
Post by Dave
I'm using ldp.exe to connect to our global catalog in order to test my ad
Base Dn: dc=abc,dc=mycompany,dc=com
Filter: (&(sAMAccountName=jsmith))
Scope: SubTree
Works fine, but how do I incorporate the 'Base Dn' attribute in the
DirectorySearcher below?
DirectoryEntry entry = new DirectoryEntry("GC://mycompany.com", user, pass);
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(&(sAMAccountName=jsmith))";;
search.SearchScope = SearchScope.Subtree;
SearchResult result = search.FindOne();
Where does the Base Dn fit above? Thanks
Dave
2005-11-30 19:11:02 UTC
Permalink
Thanks! that did the trick
Post by Joe Kaplan (MVP - ADSI)
The DirectorySearcher gets both the Base DN and the credentials used for
binding from the DirectoryEntry object that is set in the SearchRoot
property.
In your code below, to set the base DN, add that DN to the ADsPath in the
DirectoryEntry entry = new DirectoryEntry
("GC://mycompany.com/dc=abc,dc=mycompany,dc=com", user, pass,
AuthenticationTypes.Secure);
The ADsPath is essentially composed of the scheme, the server information
(which is optional with AD sometimes) and the object name, which with LDAP
(or GC), is the DN of the object.
HTH,
Joe K.
Post by Dave
I'm using ldp.exe to connect to our global catalog in order to test my ad
Base Dn: dc=abc,dc=mycompany,dc=com
Filter: (&(sAMAccountName=jsmith))
Scope: SubTree
Works fine, but how do I incorporate the 'Base Dn' attribute in the
DirectorySearcher below?
DirectoryEntry entry = new DirectoryEntry("GC://mycompany.com", user, pass);
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(&(sAMAccountName=jsmith))";;
search.SearchScope = SearchScope.Subtree;
SearchResult result = search.FindOne();
Where does the Base Dn fit above? Thanks
Loading...