Binding to Active Directory in C#

Geez I haven’t had a lot of time to blog in awhile .  I wanted to quickly put something down about how to connect to active directory using C# . If you do a search Google you will see a Ton of posts,blogs about the subject . As you can find out that there is an issue with returning a users groups . That being that you will not get the primary group (usually Domain users ) . This also affects Group membership too . The reason is because the ‘memberof’ attribute doesn’t contain primary group . So what you must use is Token groups . For me this is very confusing . Since the token groups attribute is not present by default you have to use the user.refreshcache() method .

I found another way to do this . By using this assembly from the 3.5 framework called System.DirectoryServices.Accountmanagement .

I will give an example this weekend but do a search in google . This solves the issue of missing users in groups and lists all groups a user is a member of .

Bye for now .

Chris

Advertisements