有没有办法启用 UserPrincipal.FindByIdentity() 的引用追踪?

发布于 2024-10-31 07:00:49 字数 917 浏览 3 评论 0 原文

我有一个使用 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 调用的问题。

I have a .NET 3.5 web application that uses the System.DirectoryServices.AccountManagement classes. When I search for some users I get a PrincipalOperationException: A referral was returned from the server. If I did this the old school way with my own LDAP code I could enable chasing of referrals. Do I need to rewrite my code?

My code looks like this:

   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;
            }
        }
    }

My adPath can be one of 2 values. One of the values is a domain that was recently joined, and can be accessed using different tools. I believe this is a problem with how this .NET library makes the LDAP calls.

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

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

发布评论

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

评论(2

找个人就嫁了吧 2024-11-07 07:00:49

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

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

因此,我了解如何在 Microsoft 站点和 我发现了这个,这意味着 ADSI 使用。我对答案很感兴趣。

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

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

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

Here is a partial Answer, as it's too long for a comment.

According to this Microsoft documentation, as you even know, Referrals are a hint that the client can chase. But concerning RODC they add "For example, in the case of an LDAP application, if chase referrals is enabled on the LDAP connection between the client and the RODC, the application never knows that the client received a referral from the RODC. The client is automatically redirected to the writable domain controller that is specified in the referral. ".

So I look how to enable LDAP chasing on a connexion in Microsoft site and I found this which means ADSI use. I'am very interested in the answer.

Do you try to query the global catalog like this :

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

It's supposed to contains all the forest domain's datas.
I hope it helps.

微凉徒眸意 2024-11-07 07:00:49

您是否尝试过以下形式的代码(将域作为第二个参数放入):

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

还要确保 adPath 从最具体到最不具体。

Have you tried code of the form(put the domain in as the second argument):

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

Also make sure that the adPath is from most specific to least specific.

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