UserPrincipal 对象中的域名在哪里?
- 作者: 健力宝
- 来源: 51数据库
- 2022-10-21
问题描述
我正在使用 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, "*****Login", "PWD");
DirectorySearcher dsLookForDomain = new DirectorySearcher(deBase);
dsLookForDomain.Filter = "(objectClass=*)";
dsLookForDomain.SearchScope = SearchScope.base;
dsLookForDomain.PropertiesToLoad.Add("msDS-PrincipalName");
SearchResult srcDomains = dsLookForDomain.FindOne();
- C#通过fleck实现wss协议的WebSocket多人Web实时聊天(附源码)
- 团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
- 使用 MSBuild.exe 在发布模式下构建 C# 解决方案
- 当我发布 Web 应用程序时,AfterPublish 脚本不运行
- 构建时 T4 转换的产品仅在下一个构建中使用
- ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
- 新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
- 如何将条件编译符号(DefineConstants)传递给 msbuild
- MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
- NuGet 包还原找不到包,没有源
