将用户添加到Active Directory组.net核心:服务器返回了引荐

问题描述 投票:0回答:1

我正在建立.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个回答
0
投票

我建议您查找要添加到广告中的帐户。我可以建议的其他方法是使用调试器来确认您在其下运行该域的帐户/组是否存在。

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();
    }
© www.soinside.com 2019 - 2024. All rights reserved.