简体   繁体   English

如何在.NET中获取DirectorySearcher的SearchResult的DN?

[英]How to get DN for a DirectorySearcher's SearchResult in .NET?

How can we reliably get the DN of a SearchResult ? 我们如何可靠地获取SearchResultDN

We've been using SearchResult.Properties["dn"] but recently encountered an installation where this is not supported. 我们一直在使用SearchResult.Properties["dn"]但最近遇到了不支持此安装的安装。 This customer has other applications that boil down to calling Win32's ldap_get_dn method, but there doesn't seem to be an equivalent for SearchResult in .NET. 该客户还有其他应用程序可以归结为调用Win32的ldap_get_dn方法,但.NET中似乎没有与SearchResult等效的应用程序。

The solution needs to work across LDAP servers, not ActiveDirectory-specific. 该解决方案需要跨LDAP服务器而不是特定于ActiveDirectory的工作。

It wasn't clear at first but we later found out the SearchResult.Path property contains the DN and can be parsed for it. 最初不清楚,但后来我们发现SearchResult.Path属性包含DN,可以对其进行解析。 This worked consistently with all servers we've encountered so far. 这与到目前为止我们遇到的所有服务器都一致。

SearchResult result;
...
string userDn = result.Path;

// typical Path is
// LDAP://my.ldap.server.com:39/CN=a,CN=b,OU=c
// we want to grab the part after the third '/'
int i = userDn.IndexOf('/', 7);
if (i >= 0 && userDn.Length > i + 1)
{
    userDn = userDn.Substring(i + 1);
}

SearchResult.Path Property SearchResult.Path属性

http://msdn.microsoft.com/en-us/library/system.directoryservices.searchresult.path.aspx http://msdn.microsoft.com/zh-CN/library/system.directoryservices.searchresult.path.aspx

The base object , which is always a distinguished name, is made available via the LDAP search result entry (but not a search result reference). 通过LDAP搜索结果条目(而不是搜索结果引用)可以使用始终为专有名称的base object The distinguished name is not an attribute, however. 但是,专有名称不是属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 Principal 而不是 DirectorySearcher 的 SearchResult 获取额外的 Active Directory 属性 - Get additional Active directory attributes from Principal instead of DirectorySearcher's SearchResult DirectorySearcher:如何仅获取“真实”用户的条目 - DirectorySearcher: How to get only entries for “real” users 如何模拟 System.DirectoryServices.SearchResult? - How to mock System.DirectoryServices.SearchResult? 从DN获取用户信息 - Get user information from DN 从DirectorySearcher获取2000条记录中的2000条 - Get 2000 of 6000 records from DirectorySearcher "获取分页 DirectorySearcher 的搜索结果总数" - Get total number of search results for paginated DirectorySearcher 如何在使用DirectorySearcher时确定ClientTimeout - How to determine ClientTimeout when using DirectorySearcher 如何将 PropertyValueCollection 转换为 C# 列表? (ResultPropertyCollection 和 SearchResult) - How to convert PropertyValueCollection into a List C# ? (ResultPropertyCollection and SearchResult) 如何将变量传递给DirectoryServices类的searchResult.Properties [] - How to pass a variable into the searchResult.Properties[] for the DirectoryServices class 我可以从 DirectorySearcher 中获取 1000 多条记录吗? - Can I get more than 1000 records from a DirectorySearcher?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM