C# get groups that a user is a member of in Active Directory -
i'm not programmer nature apologize in advance :) i'm using code snippets http://www.codeproject.com/articles/18102/howto-almost-everything-in-active-directory-via-c#39 , has been helpful. i'm using method getting user group memberships , requires attributevaluesmultistring method well. don't have syntax errors when call groups method via groups("username", true) following error:
an unhandled exception of type 'system.runtime.interopservices.comexception' occurred in system.directoryservices.dll
i have done digging nothing seems answer why i'm getting error.
thanks in advance!
you should check out system.directoryservices.accountmanagement (s.ds.am) namespace. read here:
- managing directory security principals in .net framework 3.5
- msdn docs on system.directoryservices.accountmanagement
basically, can define domain context , find users and/or groups in ad:
// set domain context using (principalcontext ctx = new principalcontext(contexttype.domain)) { // find user userprincipal user = userprincipal.findbyidentity(ctx, "someusername"); if(user != null) { // user's groups var groups = user.getauthorizationgroups(); foreach(groupprincipal group in groups) { // whatever need groups } } } the new s.ds.am makes easy play around users , groups in ad!
Comments
Post a Comment