C#验证AD账号是否存在

        public bool CheckUserExist(string userName)
        {
            IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();

            using (var domainContext = new PrincipalContext(ContextType.Domain, ipGlobalProperties.DomainName))
            {
                using (var foundUser = UserPrincipal.FindByIdentity(domainContext, IdentityType.SamAccountName, userName))
                {
                    return foundUser != null;
                }
            }
        }

 

posted @ 2021-02-24 20:37  来瓶冰镇可乐吧  阅读(206)  评论(0)    收藏  举报