c# - System.DirectoryServices use And limitation -
in application need fetch users email active directory.
i came across system.directoryservices namespace accessing active directory. have no idea on how works. have few questions.
can use namespace , access ad proper queries? there pre-requisite access ldap etc.
please let me know how works
fyi use .net 4.0
if you're on .net 3.5 , up, 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) { // here.... } // find group in question groupprincipal group = groupprincipal.findbyidentity(ctx, "yourgroupnamehere"); // if found.... if (group != null) { // iterate on members foreach (principal p in group.getmembers()) { console.writeline("{0}: {1}", p.structuralobjectclass, p.displayname); // whatever need members } } } the new s.ds.am makes easy play around users , groups in ad!
Comments
Post a Comment