c# - Accessing Active Directory to get User's Manager in asp.net -
i making user management module of application authenticate user credentials based on domain login details. authenticating not problem, problem need particular user's manager.
i using following method retrieve "manager" property of user:
directoryentry de = new directoryentry(path, user, pass, authenticationtypes.secure); directorysearcher ds = new directorysearcher(); ds.searchroot = new directoryentry("ldap://xyzdomain", "username", "pwd"); ds.filter = "(|(&(objectcategory=person)(objectclass=user)(mailnickname=*domainalias*)))"; //ds.propertynamesonly = true; ds.propertiestoload.add("manager"); list<string> users = new list<string>(); string s = "undefined"; foreach (searchresult sr in ds.findall()) { directoryentry dee = sr.getdirectoryentry(); s = (string)dee.properties[""].value ?? "<undefined>"; users.add(s); }
this returns me manager details in such way:
cn=first lastname,ou=managers,ou=engineering,ou=central,ou=something,dc=xyz,dc=xyz,dc=xyzre
what use string manipulation extract cn , run query on cn find details of manager. problem cn here isn't unique. there 2 or more people of same name. need method returns me manager alias of user (not cn or anything).
please highly appreciated. open suggestions. many thanks
there field called mailnickname.
this link: in active directory, mailnickname used for? has more information it. problem is: it's used exchange-server.
so means value can null or empty. here's example in visual basic: http://www.vbforums.com/showthread.php?615131-resolved-get-logged-in-user-s-alias-from-ldap explains how , what.
Comments
Post a Comment