[英]How to get DN for a DirectorySearcher's SearchResult in .NET?
How can we reliably get the DN
of a SearchResult
? 我们如何可靠地获取SearchResult
的DN
?
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.