c# - 如何在 Asp.Net 中获取用户的 AD 用户组?

标签 c# asp.net active-directory

我需要能够获取用户所在组的列表,但我需要使以下一个/一些/所有属性可见:

  • 识别名
  • 姓名
  • 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/

相关文章:

c# - 如何在ASP.net中使用OpenID

powershell - 按密码到期日期对 Get-ADUser 输出进行排序

active-directory - ADAM、事件目录、LDAP、ADFS、身份

c# - RSA用PHP签名,用C#验证

c# - 无法在 asp.net 报表查看器中查看 SQL Server 移动报表

c# - 在 ASP 中使用 foreach 与 ASP.NET View 引擎 : Repeater is not working

php - NGINX - Active Directory 单点登录

c# - 来自字节数组移位的位图

c# - 从代码隐藏 (c#) catch block 调用 JavaScript 函数

javascript - 更改中继器中的复选框 ID