我需要能够获取用户所在组的列表,但我需要使以下一个/一些/所有属性可见:
- 识别名
- 姓名
- cn
- samaccountname
我现在拥有的返回某种名称,但不是上面的任何名称(名称看起来很接近,但并非都正确匹配。这就是我正在使用的:
ArrayList groups = new ArrayList();
foreach (System.Security.Principal.IdentityReference group in System.Web.HttpContext.Current.Request.LogonUserIdentity.Groups)
groups.Add(group.Translate(typeof(System.Security.Principal.NTAccount)));
就像我说的,上面的方法有效,但不会给我程序所需的专有名称(上面指定的名称)。我需要它能够与我在调用我域中的所有组时获得的列表相匹配:
DirectoryEntry dirEnt = new DirectoryEntry("LDAP://my_domain_controller");
DirectorySearcher srch = new DirectorySearcher(dirEnt);
srch.Filter = "(objectClass=Group)";
var results = srch.FindAll();
最佳答案
您不能一步完成此操作,因为组也是具有属性的独立 AD 条目。
因此在第一次运行时,您应该获取用户所在的组名并将它们填入某种列表。
第二步是遍历所有组名并逐个查询它们以获得组属性(如 distinguishedname 等)并将其收集到某种结构。
关于c# - 如何在 Asp.Net 中获取用户的 AD 用户组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/90572/