Active Directory Question

G

Guest

Hi guys

Ok, I have an Intranet web thingy that's being running on a client's server
for months perfectly happily. It uses Active Directory through
System.Directory Services to get the logged on user, list of users etc.

Originally, all the users were stored under Domain\Users. However, it's been
changed. They're now under "Domain\CompanyUsers" - and my code has started
going a bit daft.

Here's the code I use to get a list of people from AD...

DirectoryEntry entry = new DirectoryEntry("LDAP://" +
ConfigurationSettings.AppSettings.Get("System_ActiveDirPath"));
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.Filter = ("(objectClass=user)");
foreach(SearchResult resEnt in mySearcher.FindAll())
{
try
{
DirectoryEntry de = resEnt.GetDirectoryEntry();
if((de.Properties["DisplayName"].Value != null) &&
(de.Properties["givenName"].Value != null) && (de.Properties["sn"].Value !=
null))
{
// add to list
}
}
}

which is now giving me an error. However, the following...

DirectoryEntry entry = new DirectoryEntry("LDAP://" +
ConfigurationSettings.AppSettings.Get("System_ActiveDirPath"));
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.Filter = "(&(objectClass=user)(samaccountname=" + currentUserID +
"))";
SearchResult resEnt = mySearcher.FindOne();

I think my theory can't be right, because both peices of code use
objectClass=user, and yet the top one fails.

Anything obvious to anyone?

Cheers



Dan
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top