N/APosted on - 10/31/2011
Hi everyone ,
I am creating an application in ASP.NET Web application in Visual C# .NET particularly authentication.
I read a forum on the internet and I follow the steps and the source code and its working fine using LdapAuthentication.
But my issue here is that I need to call a certain AD group in the system by using GetGroups method.
I need a code that will tell that into the system. Please help!
Help with this Code Please
Please go through the below mentioned codes to use the GetGroup method to call a certain AD group in the system.
To develop LDAP group retrieval code to look up the user's group membership
Add the following implementation of the GetGroups method to the LdapAuthentication class.
public string GetGroups()
DirectorySearcher search = new DirectorySearcher(_path);
search.Filter = "(cn=" + _filterAttribute + ")";
StringBuilder groupNames = new StringBuilder();
SearchResult result = search.FindOne();
int propertyCount = result.Properties["memberOf"].Count;
int equalsIndex, commaIndex;
for( int propertyCounter = 0; propertyCounter < propertyCount;
dn = (String)result.Properties["memberOf"][propertyCounter];
equalsIndex = dn.IndexOf("=", 1);
commaIndex = dn.IndexOf(",", 1);
if (-1 == equalsIndex)
groupNames.Append(dn.Substring((equalsIndex + 1),
(commaIndex – equalsIndex) – 1));
throw new Exception("Error obtaining group names. " +
This will help to solve your query.