UserPrincipals.GetAuthorizationGroups An error (1301) occurred while enumerating the groups. After upgrading to Server 2012 Domain Controller

后端 未结 10 1303
陌清茗
陌清茗 2020-12-29 21:17

Research:

Similar Issue with workaround, but not actual solution to existing problem

Similar issue pointing to Microsoft End Point update as

10条回答
  •  梦谈多话
    2020-12-29 22:08

    Facing the same problem enumerating authorization groups and the patches noted in the answer did not apply to our web server.

    Manually enumerating and ignoring the trouble causing groups is working well, however:

    private static bool UserIsMember(string usr, string grp)
    {
        usr = usr.ToLower();
        grp = grp.ToLower();
    
        using (var pc = new PrincipalContext(ContextType.Domain, "DOMAIN_NAME"))
        {
            using (var user = UserPrincipal.FindByIdentity(pc, usr))
            {
                var isMember = false;
                var authGroups = user?.GetAuthorizationGroups().GetEnumerator();
    
                while (authGroups?.MoveNext() ?? false)
                {
                    try
                    {
    
                        isMember = authGroups.Current.Name.ToLower().Contains(grp);
                        if (isMember) break;
                    }
                    catch
                    {
                        // ignored
                    }
                }
    
                authGroups?.Dispose();
                return isMember;
            }
        }
    }
    

提交回复
热议问题