查询从LDAP为用户组 [英] Query From LDAP for User Groups

查看:325
本文介绍了查询从LDAP为用户组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取用户的用户群从C#.NET的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为用户组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆