I have written a Web Based Login Module in C# that authenticates against my local PDC. As far as the authentication goes, it works great. The problem comes when I try to get all the groups the user logging in belongs to. And whatâs even WEIRDER is that it works fine when I run it from the development box (which is where the program resides and runs) but when I run (access it) it from another computer it will NOT get the group membership! Hereâs the code I use (Keep in mind the strUser has already been authenticated against the AD):
Code:
string getGroups (string strUser){
DirectoryEntry obEntry = new DirectoryEntry(
"LDAP://DC=courthousedata,DC=com");
DirectorySearcher srch = new DirectorySearcher(obEntry,
"(sAMAccountName=" + strUser + ")");
SearchResult res = srch.FindOne();
if (null != res){
DirectoryEntry obUser = new DirectoryEntry(res.Path);
object obGroups = obUser.Invoke("Groups");
foreach (object ob in (IEnumerable)obGroups){
DirectoryEntry obGpEntry = new DirectoryEntry(ob);
groupNames.Append(obGpEntry.Name);
groupNames.Append("|");
}
}
return groupNames.ToString();
}
In IIS I have setup a user that has the ability to read the AD. (Again this works from the local machine, even if in the local machine I change from
http://localhost to
http://nameofbox it still works)
Any Help is appreciated!