有没有办法为UserPrincipal.FindByIdentity()启用引荐追逐?

LDA*_*mer 6 c# windows ldap active-directory windows-server

我有一个使用System.DirectoryServices.AccountManagement类的.NET 3.5 Web应用程序.当我搜索一些用户时,我得到一个PrincipalOperationException:从服务器返回一个引用.如果我使用自己的LDAP代码执行旧学校的方式,我可以启用追踪推荐.我需要重写我的代码吗?

我的代码看起来像这样:

   using (var principalContext = new PrincipalContext(ContextType.Domain, null, adPath))
    {

        // Find the principal object for which you wish to enumerate group
        // membership.
        using (var userPrincipal = UserPrincipal.FindByIdentity(principalContext, identity))
        {
            if (userPrincipal != null)
            {
                Name = userPrincipal.DisplayName;
                DistinguishedName = userPrincipal.DistinguishedName;
                EmailAddress = userPrincipal.EmailAddress;
                Sid = userPrincipal.Sid.Value;
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

我的adPath可以是2个值中的一个.其中一个值是最近加入的域,可以使用不同的工具进行访问.我相信这是.NET库如何进行LDAP调用的问题.

JPB*_*anc 1

这是部分答案,因为评论太长。

根据此 Microsoft 文档,正如您所知,推荐是客户可以追逐的提示。但对于 RODC,他们添加了“例如,在 LDAP 应用程序的情况下,如果在客户端和 RODC 之间的 LDAP 连接上启用了追踪引用,则应用程序永远不会知道客户端收到了来自 RODC 的引用。客户端是自动重定向到引用中指定的可写域控制器。 ”。

因此,我查看了如何在 Microsoft 站点的连接上启用 LDAP 追踪,我发现这意味着 ADSI 使用。我对答案很感兴趣。

您是否尝试像这样查询全局目录:

/* Retreiving a principal context
 */
PrincipalContext domainContext = new PrincipalContext(ContextType.Domain, "YourGCServer:3268", "dc=dom,dc=fr", "User", "Password");
Run Code Online (Sandbox Code Playgroud)

它应该包含林域的所有数据。我希望它有帮助。