考虑以下在Active Directory中为用户设置的属性:
在我的winforms应用程序中,我想显示当前登录并使用该应用程序的用户的显示名称。 我应该如何检索此信息?
考虑以下在Active Directory中为用户设置的属性:
在我的winforms应用程序中,我想显示当前登录并使用该应用程序的用户的显示名称。 我应该如何检索此信息?
既然您使用的是.NET 4,您可以使用System.DirectoryServices.AccountManagement
(S.DS.AM)命名空间。点击此链接了解更多信息:
基本上,您可以定义一个域上下文并轻松地查找AD中的用户和/或组:
// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
// find currently logged in user
UserPrincipal user = UserPrincipal.Current;
string displayName = user.DisplayName;
新的S.DS.AM使在AD中玩弄用户和组变得非常容易。
经过几个小时的寻找,我终于找到了最简单的方法。
System.DirectoryServices.AccountManagement.UserPrincipal.Current.DisplayName;
我希望让更多像我一样的人知道这件事。
ctx
- 对于这个单独的语句来说并不是必需的。 - marc_sThe LDAP server is unavailable.
- AgentFire