M
Maziar Aflatoun
Hi everyone,
I'm having a problem with reading user groups on Active Directory using C#.
It returns all the groups in the Universal scope for a specific user.
However, I only need the groups in Global scope and Domain local scope. Does
anyone know I can modify the following code to this?
DirectoryEntry entry = new DirectoryEntry("LDAP://" + Domain, CurrentUser,
pwd, AuthenticationTypes.Secure);
DirectorySearcher mySearcher = new DirectorySearcher(entry);
// Change this search for anything
mySearcher.Filter = ("(sAMAccountName="+CurrentUser+")");
try
{
System.DirectoryServices.SearchResult resEnt = mySearcher.FindOne();
// Display all groups for this user
object obGroups = de.Invoke("Groups");
foreach (object ob in (IEnumerable)obGroups)
{
DirectoryEntry obGpEntry = new DirectoryEntry(ob);
group = obGpEntry.Name.Replace("CN=", "");
Response.Write("Group: " + group + "<br>");
}
....
Thank you
Maz A.
I'm having a problem with reading user groups on Active Directory using C#.
It returns all the groups in the Universal scope for a specific user.
However, I only need the groups in Global scope and Domain local scope. Does
anyone know I can modify the following code to this?
DirectoryEntry entry = new DirectoryEntry("LDAP://" + Domain, CurrentUser,
pwd, AuthenticationTypes.Secure);
DirectorySearcher mySearcher = new DirectorySearcher(entry);
// Change this search for anything
mySearcher.Filter = ("(sAMAccountName="+CurrentUser+")");
try
{
System.DirectoryServices.SearchResult resEnt = mySearcher.FindOne();
// Display all groups for this user
object obGroups = de.Invoke("Groups");
foreach (object ob in (IEnumerable)obGroups)
{
DirectoryEntry obGpEntry = new DirectoryEntry(ob);
group = obGpEntry.Name.Replace("CN=", "");
Response.Write("Group: " + group + "<br>");
}
....
Thank you
Maz A.