Dear All!
I am not very familiar with working with LDAP. I have created a webapp integrated with LDAP, logged OK. I want to get the group name of a logged user, how can i do that?
I did search on google and have read the article from codeproject, but it doesn't help me to find out the group name. any responses will be very appreciated!
Many thanks
Hoang An
Loading

Suthish NairRank #92 · 22.8K reputationPosted Jul 26, 2011, 4:09 AM EDT
Suthish NairRank #92 · 22.8K reputationPosted Jul 24, 2011, 11:48 PM EDT
Integrating LDAP Active Directory into your .Net Web Portal (C# or VB.NET)
Hoang An16 reputationPosted Jul 24, 2011, 11:55 PM EDT
Hoang An
Suthish NairRank #92 · 22.8K reputationPosted Jul 25, 2011, 4:03 AM EDT
refer might helps:
Link1 Link2 Link3 Link4
Hoang An16 reputationPosted Jul 26, 2011, 1:05 AM EDT
Using Link 1, i have found the solution for getting group user name base on logged on user name. Below is the method:
public String GetGroupUserName(String UserName, String Password, String Domain)
{
DirectoryEntry entry = new DirectoryEntry("LDAP://"+Domain, UserName, Password);
DirectorySearcher search = new DirectorySearch();
seach.SearchRoot=entry;
search.Filter="(SAMAccountName="+UserName+")";
search.PropertiesToLoad.Add("memberOf");
try
{
SearchResult result=search.FindOne();
int propertyCount=result.Properties["memberOf"].Count;
string dn=String.Empty;
for(int propertyCounter=0;propertyCounter
{
dn=(string)result.Properties["memberOf"][propertyCounter];
dn=dn.Remove(dn.LastIndexOf(",OU="));
dn=dn.Replace("CN=","");
}
return dn;
}
catch(Exception ex)
{
throw ex;
}
}
Hoang An16 reputationPosted Jul 28, 2011, 11:03 PM EDT