How to get memberOf groups for a user in ldap ?

G

Guest

Hi,

I am trying to autheticate a user in ldap and get a list of all the groups
the the use is a member of. My problem is that i only get one groups from the
request, although i know i am memeber of several groups.

Can anyone see what i am doing wrong here?

public bool IsAuthenticated(string domain, string username, string pwd)
{
//using System.DirectoryServices;

string domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd);

try
{
DirectorySearcher search = new DirectorySearcher(entry);

search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();

if(null == result)
{
return false;
}


_path = result.Path; //Update the new path to the user in the directory.
//_filterAttribute = (string)result.Properties["cn"][0];
}
catch (Exception ex)
{
label4.Text = ex.Message;
return false;
}

ListMemberOfGroups(_path);
return true;
}

public void ListMemberOfGroups(string path)
{
DirectoryEntry entry = new DirectoryEntry(path);
DirectorySearcher search = new DirectorySearcher(entry);

search.PropertiesToLoad.Add("memberOf");

try
{
foreach(System.DirectoryServices.SearchResult resEnt
in search.FindAll())
{
string res =
resEnt.GetDirectoryEntry().Properties["memberOf"].Value.ToString();
lb1.Items.Add(res);
}
}
catch(Exception ex)
{
lb1.Items.Add(ex.Message);
}
}
 
O

Ollie

you are best asking the two Joes in the microsoft.public.adsi.general

HTH

Ollie Riches
 

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