Click here to Skip to main content
15,438,113 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I'm implementing AD authentication for some applications.

I can get the authentication to work but i want to get what groups the user is apart of. I can get a list of ALL groups but i want to search a specific path

i have my ldap string: "LDAP://192.168.XXX.XXX" and i want to search specifically for memberships in the following group: "OU=Software,DC=dom,DC=local".

AD structure is as follows:
C#
Root
    -Software
        -Developers
        -Group 1
        -Group 2 


The purpose of doing this is to create access control based on the groups they are a part of.
Posted
Updated 23-Jan-13 9:54am
v4
Comments
Zoltán Zörgő 23-Jan-13 16:28pm     CRLF
1, this is not a MembershipPrivider related topic, it is related to the RoleProvider topic. 2, you should not use ldap to connect to AD, use the tools from DirectoryServices namespace 3, with this approach, you will have performance issues; you should not retrieve all groups a user belongs to, you should limit the search to the few groups that are roles in your application

1 solution

Try this:

C#
// create context for domain
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

// find the user
UserPrincipal up = UserPrincipal.FindByIdentity(ctx, "YourUserName");

if(up != null)
{
    // get groups for that user
    var authGroups = up.GetAuthorizationGroups();
}


Cheers,
Edo
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900