Active Director Domain AD域验证

public bool checkADGroup(string initial)
        {
            
            string ADGroup = "IT-Support";//域内组名
            string Domain = "xx.xxxxx.net";//域名
            if (ADGroup == "NA")
            {
                return true;
            }
            string container = Domain.Replace(".", ",DC=");
            PrincipalContext domainctx = new PrincipalContext(ContextType.Domain, Domain.Split('.')[0], "DC=" + container);
            UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(domainctx,IdentityType.SamAccountName,initial);
            bool isMember = userPrincipal.IsMemberOf(domainctx,IdentityType.Name,ADGroup);

            return isMember;

        }

 

posted on 2022-07-20 17:08  张不胖  阅读(51)  评论(0编辑  收藏  举报

导航