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

发布于 2024-12-21 18:14:55 字数 290 浏览 4 评论 0原文

我们如何可靠地获取 SearchResultDN

我们一直在使用 SearchResult.Properties["dn"],但最近遇到了不支持此功能的安装。该客户还有其他应用程序可以归结为调用 Win32 的 ldap_get_dn 方法,但 .NET 中似乎没有与 SearchResult 等效的方法。

该解决方案需要跨 LDAP 服务器工作,而不是特定于 ActiveDirectory。

How can we reliably get the DN of a SearchResult?

We've been using SearchResult.Properties["dn"] but recently encountered an installation where this is not supported. 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.

The solution needs to work across LDAP servers, not ActiveDirectory-specific.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌路终见情 2024-12-28 18:14:55

起初并不清楚,但后来我们发现 SearchResult.Path 属性包含 DN 并且可以对其进行解析。这与我们迄今为止遇到的所有服务器一致。

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 属性

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

It wasn't clear at first but we later found out the SearchResult.Path property contains the DN and can be parsed for it. 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

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

末が日狂欢 2024-12-28 18:14:55

基本对象始终是一个专有名称,可通过 LDAP 搜索结果条目(但不是搜索结果引用)使用。然而,专有名称不是属性。

The base object, which is always a distinguished name, is made available via the LDAP search result entry (but not a search result reference). The distinguished name is not an attribute, however.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文