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);
}
}
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);
}
}