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
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