.net - Getting extra ad attributes from UserPrincipal -
i have below code user's total name logon name:
public view getuser(string suser) { view oview = new view(); oview.user = suser.toupper(); using (principalcontext oprincipalcontext = new principalcontext(contexttype.domain, "varner.no")) { userprincipal ouserprincipal = userprincipal.findbyidentity(oprincipalcontext, oview.user); oview.name = ouserprincipal.displayname; homecoming oview; } } }
but need other attributes code. in case need "ipphone" attribute ad. possible or need utilize directorysearcher directoryentry?
you can extending userprincipal you'll find short illustration here under , more info in msdn documentation.
class dsprincipals { static void main(string[] args) { /* retreiving principal context */ principalcontext domaincontextmonou = new principalcontext(contexttype.domain, "wm2008r2ent:389", "ou=monou,dc=dom,dc=fr", "jpb", "pass@1w0rd01"); /* create user principal object */ slxuser aslxuser = new slxuser(domaincontextmonou, "w.zeidan", "pass@1w0rd01", true); /* assign properties user principal */ aslxuser.givenname = "wessam"; aslxuser.surname = "zeidan"; aslxuser.streetaddress = "add1"; /* forcefulness user alter password @ next logon */ aslxuser.expirepasswordnow(); /* save user directory */ aslxuser.save(); console.readline(); } } [directoryobjectclass("user")] [directoryrdnprefix("cn")] class slxuser : userprincipal { public slxuser(principalcontext context) : base(context) { } public slxuser(principalcontext context, string samaccountname, string password, bool enabled ) : base(context, samaccountname, password, enabled) { } [directoryproperty("streetaddress")] public string streetaddress { { object[] result = this.extensionget("streetaddress"); if (result != null) { homecoming (string)result[0]; } else { homecoming null; } } set { this.extensionset("streetaddress", value); } } }
.net active-directory userprincipal
No comments:
Post a Comment