3

我有一个 .NET 3.5 方法,给定一个用户和一个 Active Directory 组列表,返回用户所属的组子集。该代码适用于数十个安装,但在一个特定的客户站点失败。代码如下所示:

List<GroupAttrs> ret = new List<GroupAttrs>();

foreach (SymDomainInfo domain in domains)
{
   using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain, domain.Name, adUser, adPwd))
   {
      foreach (GroupAttrs aGroup in grpAttrs)
      {
         if (aGroup.Available)
                continue;

             GroupPrincipal pGroup;

             try
             {
                 pGroup = GroupPrincipal.FindByIdentity(ctx, IdentityType.Sid, aGroup.Authid);
             }
             catch (Exception e3)
             {
                 Console.WriteLine("{3} finding group {0}/{4} in domain {1}: {2}", aGroup.Name, domain.Name, e3.Message, e3.GetType().Name, aGroup.Authid);

                 if (e3.InnerException != null)
                    Console.WriteLine("\tInner {0}: {1}", e3.InnerException.GetType().Name, e3.InnerException.Message);

                 continue;
             }

             if (pGroup != null)
             {
                Console.WriteLine("Found Group " + pGroup.DistinguishedName);
                FindUserInGroup(grpMap, identity.User, ret, pGroup);
             }
          }
   }
}

AGroupAttrs是我们自己的数据库类,其中包含 Active Directory 组的名称和 SID(在字段中AuthID)。该集合SymDomainInfos包含 AD 中所有受信任域的名称和路径。和是有权搜索 AD 的域用户的凭据adUseradPassword

循环的每次迭代都会给出相同的错误:

System.ArgumentException:值无效。参数名称: System.DirectoryServices.AccountManagement.ADStoreCtx.FindPrincipalByIdentRefHelper(Type principalType, String urnScheme, String urnValue, DateTime referenceDate, Boolean useSidHistory)
at System.DirectoryServices 的 sddlForm。 AccountManagement.ADStoreCtx.FindPrincipalByIdentRef(类型 principalType,字符串 urnScheme,字符串 urnValue,DateTime referenceDate) 在 System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext 上下文,类型 principalType,Nullable`1 identityType,字符串 identityValue,DateTime refDate)



在 System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithType(PrincipalContext context, Type principalType, IdentityType identityType, String identityValue)
在 System.DirectoryServices.AccountManagement.GroupPrincipal.FindByIdentity(PrincipalContext context, IdentityType identityType, String identityValue)
在 ADGroupsTest.Program.Main(字符串 [] 参数)

我们还有另一位客户,这对我们不起作用。错误不同,该客户已删除或禁用 Active Directory 中的一些默认属性。当他们恢复这些属性时,代码开始工作。所以我的猜测是,这个客户已经以某种方式配置了他们的 AD,这样GroupPrincipal.FindByIdentity在从域上下文调用时将无法工作。

所以我的问题是:有人知道什么类型的 AD(错误)配置会导致这个特定的错误吗?失败了,谁能告诉我FindByIdentity在这种情况下必须实施哪些 AD 属性才能工作?

4

0 回答 0