gpt4 book ai didi

c# - 如何连接到 RootDSE 和/或使用 System.DirectoryServices.Protocols 检索 highestCommittedUSN?

转载 作者:太空宇宙 更新时间:2023-11-03 21:40:15 27 4
gpt4 key购买 nike

使用 System.DirectoryServices,可以通过这种方式获得最高的 CommittedUSN:

using(DirectoryEntry entry = new DirectoryEntry("LDAP://servername:636/RootDSE"))
{
var usn = entry.Properties["highestCommittedUSN"].Value;
}

但是,我需要使用不利用 ADSI 的 System.DirectoryServices.Protocols 从远程 ADLDS 获取此信息。以下是我正在尝试执行的操作的简化代码示例:

using(LdapConnection connection = GetWin32LdapConnection())
{
var filter = "(&(highestCommittedUSN=*))";
var searchRequest = new SearchRequest("RootDSE", filter, SearchScope.Subtree, "highestCommittedUSN");
var response = connection.SendRequest(searchRequest) as SearchResponse;
var usn = response.Entries[0].Attributes["highestCommittedUSN"][0];
}

不幸的是,这会引发“DirectoryOperationException:专有名称包含无效语法”。起初我认为 GetWin32LdapConnection() 中可能有问题,但在许多其他地方调用该代码以连接到目录并且永远不会出错。

有什么想法吗?

最佳答案

感谢 Zilog 的想法。显然要连接到 RootDSE,您必须为根容器指定 null。我还将过滤器切换为 objectClass=* 并将搜索范围切换为“base”。现在可以了!

using(LdapConnection connection = GetWin32LdapConnection())
{
var filter = "(&(objectClass=*))";
var searchRequest = new SearchRequest(null, filter, SearchScope.Base, "highestCommittedUSN");
var response = connection.SendRequest(searchRequest) as SearchResponse;
var usn = response.Entries[0].Attributes["highestcommittedusn"][0];
}

我希望这能在将来为其他人节省一些时间。

关于c# - 如何连接到 RootDSE 和/或使用 System.DirectoryServices.Protocols 检索 highestCommittedUSN?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19696753/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com