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 NairPosted Jul 26, 2011, 8:09 AM
Hoang AnPosted Jul 29, 2011, 3:03 AM
Hoang AnPosted Jul 26, 2011, 5:05 AM
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;
}
}
Suthish NairPosted Jul 25, 2011, 8:03 AM
refer might helps:
Link1 Link2 Link3 Link4
Hoang AnPosted Jul 25, 2011, 3:55 AM
Hoang An
Suthish NairPosted Jul 25, 2011, 3:48 AM
Integrating LDAP Active Directory into your .Net Web Portal (C# or VB.NET)