How to get Active Directory Attributes not represented by the UserPrincipal class

后端 未结 3 1183
自闭症患者
自闭症患者 2020-12-09 03:02

What I mean is that right now I am using System.DirectoryServices.AccountManagement and if I use UserPrincipal class I only see the Name, Middle Name, etc

so in my c

3条回答
  •  既然无缘
    2020-12-09 03:53

    In this case, you need to go one level deeper - back into the bowels of DirectoryEntry - by grabbing it from the user principal:

    using (DirectoryEntry de = myUser.GetUnderlyingObject() as DirectoryEntry)
    {
        if (de != null)
        {
            // Go for those attributes and do what you need to do...
            var mobile = de.Properties["mobile"].Value as string;
            var info = de.Properties["info"].Value as string;
        }
    }
    

提交回复
热议问题