Using the DirectoryEntry and DirectorySearcher Classes.

S

Sezgin Rafed

Hi everyone,

I need to select Users from 2 Domains - one the User has logged into and a
second one, which is a trusted Domain.
There is no problem selecting Users from the Domain the User has logged
into. When trying to query the trusted Domain I get the "a referral was
returned by the server" error message and no results -
SearchResultCollection has no items.
Any help solving the problem will be greatly appreciated. Code snippet
bellow.

Regards.


private void QueryObjects()
{
string myADSPath = "LDAP://DC=mysubdomain,DC=mydomain,DC=com";
string Username = "(e-mail address removed)";
string Password = "mypassword";

DirectoryEntry de= new
DirectoryEntry(myADSPath,Username,Password,AuthenticationTypes.Secure);

DirectorySearcher ds = new DirectorySearcher(de);
ds.PropertyNamesOnly = true;
ds.PropertiesToLoad.Add("name");

Cursor currentCursor = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;

// start searching
SearchResultCollection src = ds.FindAll();
try
{
foreach (SearchResult sr in src)
AddObjectToTree(sr.GetDirectoryEntry()); //adds results to treeview
node
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
src.Dispose();
ds.Dispose();
Cursor.Current = currentCursor;
}
 
M

Marc Scheuner [MVP ADSI]

I need to select Users from 2 Domains - one the User has logged into and a
second one, which is a trusted Domain.
There is no problem selecting Users from the Domain the User has logged
into. When trying to query the trusted Domain I get the "a referral was
returned by the server" error message and no results -
SearchResultCollection has no items.

You might want to have a close look at the DirectorySearcher's
"ReferralChasing" property - you can set it to various values.

Marc
================================================================
Marc Scheuner May The Source Be With You!
Berne, Switzerland m.scheuner -at- inova.ch
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top