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

时间:2011-04-06 21:39:37

标签: c# windows active-directory ldap 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;
            }
        }
    }

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

2 个答案:

答案 0 :(得分:1)

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

根据this Microsoft documentation,您甚至知道,推介是客户可以追逐的暗示。但是关于RODC,他们添加“例如,在LDAP应用程序的情况下,如果在客户端和RODC之间的LDAP连接上启用了追踪引用,则应用程序永远不会知道客户端从RODC接收了引用。客户端会自动重定向到引用中指定的可写域控制器。“。

所以我看看如何在Microsoft站点和I found this中启用LDAP追踪连接,这意味着使用ADSI。我对答案非常感兴趣。

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

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

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

答案 1 :(得分:0)

您是否尝试过表单的代码(将域名作为第二个参数):

var principalContext = new PrincipalContext(ContextType.Domain, "office.local", "OU=Users, DC=office, DC=local" ))

同时确保adPath从最具体到最不具体。

相关问题