我有一个函数可以返回用户所在的 AD 组列表。
public static List<string> GetGroupNames(string userName)
{
using (var context = new PrincipalContext(ContextType.Domain, Environment.UserDomainName))
{
using (var userPrincipal = UserPrincipal.FindByIdentity(context, userName))
{
var groupSearch = userPrincipal.GetGroups(context);
var result = new List<string>();
groupSearch.ToList().ForEach(sr => result.Add(sr.SamAccountName));
return result;
}
}
}
这正如我所料。我想更新这个函数,这样我就可以传递一个 LDAP 路径来指定我想要查询的域。
我已经搜索了几个小时并且可以找到任何指针(即使我确信答案就在某个地方!)我非常感谢这里的任何帮助。