且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

查看用户是否属于 C# + Asp.net 中的 Active Directory 组

更新时间:2023-02-21 10:37:09

With 3.5 and System.DirectoryServices.AccountManagement 这更简洁一些:

With 3.5 and System.DirectoryServices.AccountManagement this is a bit cleaner:

public List<string> GetGroupNames(string userName)
{
  var pc = new PrincipalContext(ContextType.Domain);
  var src = UserPrincipal.FindByIdentity(pc, userName).GetGroups(pc);
  var result = new List<string>();
  src.ToList().ForEach(sr => result.Add(sr.SamAccountName));
  return result;
}

推荐文章