5

我是访问 Active Directory 的新手,有人建议我使用System.DirectoryServices.AccountManagement,但我找不到该initials变量有任何帮助?

4

1 回答 1

11

您可以执行以下操作之一:

1)您可以扩展普通UserPrincipal类以包含您经常需要的其他项目。这将是最干净的解决方案,真的。请参阅有关扩展用户主体的 MSDN 文档,或回答此 SO 问题以获取有关如何UserPrincipal使用其他属性扩展类的示例

2)您可以“深入”到底层证券的深处DirectoryEntry并从那里获取数据:

    DirectoryEntry de = YourUserPrincipal.GetUnderlyingObject() as DirectoryEntry;

    if(de != null)
    {  
       var initials = de.Properties["initials"];

       if(initials != null && initials.Count > 0)
       {
          string theInitials = de.Properties["initials"][0].ToString();
       }
    }
于 2011-12-12T11:27:30.500 回答