查询从LDAP为用户组用户组、LDAP

由网友(淡若天涯)分享简介:如何获取用户的用户群从C#.NET的ASP LDAP活动目录。在我的情况我想通过用户名从LDAP活动目录哪个查询并告诉我,我的用户是该用户组成员方法。请帮我在这How To Get User group of user from LDAP active directory in C# .NET for ASP. In...

如何获取用户的用户群从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

阅读全文

相关推荐

最新文章