【问题标题】:Adding user to Active Directory Group .net core: A referral was returned from the server将用户添加到 Active Directory 组 .net 核心:从服务器返回了一个引用
【发布时间】:2020-05-17 00:36:35
【问题描述】:

我正在构建一个 .net core 3 网站,尝试将用户添加到 Active Directory 安全组。以下代码在我的开发环境中运行良好,但一旦部署到 IIS,我就会收到:

System.DirectoryServices.DirectoryServicesCOMException (0x8007202B): 从服务器返回了一个推荐。

错误发生在“group.Save();”

    using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, "ad.xxx.com:389", 
    "DC=ad,DC=xxx,DC=com", svcAccountUsername, svcAccountPw))
    {
       GroupPrincipal group = GroupPrincipal.FindByIdentity(pc, IdentityType.SamAccountName, groupName);
       group.Members.Add(pc, IdentityType.SamAccountName, username);
       group.Save();
    }

同样,这在我的开发环境中本地工作,但一旦部署到 IIS 就不行。有关如何修复的任何建议?

【问题讨论】:

    标签: asp.net-core iis .net-core active-directory directoryservices


    【解决方案1】:

    我建议查找您尝试添加到 AD 的帐户。我可以建议的其他事情是使用调试器来确认帐户/组存在于您正在运行它的域中。

    using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, "domain" ...))
        {
           GroupPrincipal group = GroupPrincipal.FindByIdentity(pc, IdentityType.SamAccountName, groupName);
           // Do some validation / logging to make sure there is a group returned.
    
           var principal = Principal.FindByIdentity(pc, IdentityType.SamAccountName, username);
           // Do some validation here to make sure principal is not null
    
           group.Members.Add(principal);
           group.Save();
        }
    

    确保运行此脚本的服务器有权访问您正在更新的域。

    【讨论】:

      【解决方案2】:

      推荐意味着您没有与正确的服务器交谈,但服务器知道您应该与谁交谈。如果您进一步研究异常对象,您甚至可能会发现它要将您发送到哪个服务器。

      如果该组与您传递给PrincipalContext 的域不同,则可能会发生这种情况。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-01-20
        • 1970-01-01
        相关资源
        最近更新 更多