问题描述
我使用Active Directory登录在我的WinForms应用程序之一。我得到一个 UserPrincipal
对象,但我不知道如何从这个对象适当的帐户名?我可以看到,有一个 SAM帐户
这是一样的我的帐户名,但它指出,这是旧版本的Windows。那么,如何才能获得正确的帐户名称没有马瑟新的或旧的Windows系统?
这是在code我用它来获取对象
如果(ADUserName.Length大于0)
上下文=新PrincipalContext(ContextType.Domain,广告服务器,空,ADUserName,ADUserPassword);
其他
上下文=新PrincipalContext(ContextType.Domain,广告服务器);
UserPrincipal.FindByIdentity(背景下,帐户)
SAM帐户
的是的在帐户名因为有人甚至的在的活动目录中引入在Windows中使用。
这是传统的,因为它已经被补充额外的信息 - 在LDAP环境等你的专有名称 - 但它的的是的 Windows帐户名(简称) - 这仍然是一个必填字段的任何新用户正在创建 - 只是用它
请参阅用户命名属性更多细节上的名字是用来做什么的在AD环境。
I am using Active Directory login in one of my Winforms applications. I get a UserPrincipal
object but I'm not sure how to get the proper accountname from this object? I can see that there is a SamAccountName
that is the same as my account name but it states that this is for old versions of Windows. So how do I get the proper account name no mather old or new Windows systems?
This is the code I use to get the object
if (ADUserName.Length > 0)
context = new PrincipalContext(ContextType.Domain, ADServer, null, ADUserName, ADUserPassword);
else
context = new PrincipalContext(ContextType.Domain, ADServer);
UserPrincipal.FindByIdentity(context, account)
SamAccountName
is the "account name" as it was used in Windows even before Active Directory was introduced.
It's "legacy" in that it has been supplemented by additional info - your "distinguished name" in the LDAP context etc. - but it is the Windows account name ("short name") - and it's still a mandatory field for any new user being created - just use it!
See User naming attributes for more details on which name is used for what in an AD context.
这篇关于我如何获得UserPrincipal帐户名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!