如何在 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 查询用户组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!