Query From LDAP for User Groups(从 LDAP 查询用户组)
问题描述
如何在 C# .NET for ASP 中从 LDAP 活动目录中获取用户组.在我的场景中,我想将用户名传递给从 LDAP 活动目录查询的方法,并告诉我我的用户是该用户组的成员.请帮助我
How To Get User group of user from LDAP active directory in C# .NET for ASP. In my Scenario I want to Pass user name to method which query from LDAP Active directory and tell me my user is Member of This User Groups. Please help me in this
推荐答案
如果您使用的是 .NET 3.5 或更高版本,您还可以使用新的 System.DirectoryServices.AccountManagement (S.DS.AM) 命名空间.
If you're on .NET 3.5 or newer, you can also use the new System.DirectoryServices.AccountManagement (S.DS.AM) namespaces.
有了这个,您可以执行以下操作:
With this, you can do something like:
// create context for domain
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
// find the user
UserPrincipal up = UserPrincipal.FindByIdentity(ctx, "YourUserName");
if(up != null)
{
// get groups for that user
var authGroups = up.GetAuthorizationGroups();
}
阅读有关新 S.DS.AM 命名空间的更多信息:
Read more about the new S.DS.AM namespace:
在 .NET Framework 3.5 中管理目录安全主体
这篇关于从 LDAP 查询用户组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 LDAP 查询用户组
基础教程推荐
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
