Where is the domain name in a UserPrincipal object?(UserPrincipal 对象中的域名在哪里?)
问题描述
我正在使用 System.DirectoryServices.ActiveDirectory 类来查找所有 Active Directory 用户.代码很简单:
I'm using the System.DirectoryServices.ActiveDirectory classes to find all Active Directory users. The code is very simple:
var context = new PrincipalContext(ContextType.Domain);
var searcher = new PrincipalSearcher(new UserPrincipal(context));
var results = searcher.FindAll();
我想以友好"(又名Windows 2000 之前"格式)获取域限定用户名,例如.CONTOSOSmithJ".UserPrincipal.SamAccountName 给了我用户名部分,但我如何获得域部分?我不能假设域将与机器或当前用户的域相同.
I want to get the domain-qualified username in the "friendly" (aka. "pre-Windows 2000" format), eg. "CONTOSOSmithJ". UserPrincipal.SamAccountName gives me the username part, but how do I get the domain part? I cannot assume that the domain will be the same as the machine's or current user's domain.
推荐答案
对于 AD DS,msDS-PrincipalName 的值是 NetBIOS 域名,后跟一个反斜杠(").
For AD DS, the value of msDS-PrincipalName is the NetBIOS domain name, followed by a backslash ("").
您可以使用:
/* Retreiving the root domain attributes
*/
sFromWhere = "LDAP://DC_DNS_NAME:389/dc=dom,dc=fr";
DirectoryEntry deBase = new DirectoryEntry(sFromWhere, "AdminLogin", "PWD");
DirectorySearcher dsLookForDomain = new DirectorySearcher(deBase);
dsLookForDomain.Filter = "(objectClass=*)";
dsLookForDomain.SearchScope = SearchScope.base;
dsLookForDomain.PropertiesToLoad.Add("msDS-PrincipalName");
SearchResult srcDomains = dsLookForDomain.FindOne();
这篇关于UserPrincipal 对象中的域名在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UserPrincipal 对象中的域名在哪里?
基础教程推荐
- 全局 ASAX - 获取服务器名称 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
