从LDAP查询用户组

Ars*_*aiz 9 c# asp.net ldap active-directory activedirectorymembership

如何从C#.NET for ASP中的LDAP活动目录中获取用户组用户.在我的场景中,我想将用户名传递给从LDAP Active目录查询的方法,并告诉我我的用户是此用户组的成员.请帮帮我

mar*_*c_s 12

如果您使用的是.NET 3.5或更高版本,则还可以使用新的System.DirectoryServices.AccountManagement(S.DS.AM)命名空间.

有了这个,你可以做类似的事情:

// 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();
}
Run Code Online (Sandbox Code Playgroud)

阅读有关新S.DS.AM名称空间的更多信息:

管理.NET Framework 3.5中的目录安全性主体