从 LDAP 查询用户组
如何在 C# .NET for ASP 中从 LDAP 活动目录获取用户的用户组。在我的场景中,我想将用户名传递给从 LDAP Active Directory 查询的方法,并告诉我我的用户是该用户组的成员。请在这方面帮助我
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果您使用的是 .NET 3.5 或更高版本,您还可以使用新的 System.DirectoryServices.AccountManagement (S.DS.AM) 命名空间。
有了这个,您可以执行以下操作:
阅读有关新 S.DS.AM 命名空间的更多信息:
管理目录安全.NET Framework 3.5 中的主体
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:
Read more about the new S.DS.AM namespace:
Managing Directory Security Principals in the .NET Framework 3.5
研究使用 System.DirectoryServices 命名空间。您可以使用 DirectorySearcher 查找用户。一旦您拥有该用户的 DirectoryEntry 对象,请执行此操作:
这将返回一个字符串列表,这些字符串是用户所属的组名称。
当然,您可以进一步细化它以包含 DirectorySearcher 代码,这样您就可以只向函数传递 samAccountName。
Look into using the System.DirectoryServices namespace. You can use a DirectorySearcher to find the user. Once you have the DirectoryEntry object for that user do this:
This will return a list of strings which are the group names the user is a member of.
Of course you could further refine this to include the DirectorySearcher code so you can just pass the function the samAccountName.
试试这个...
try this...
使用 DirectorySearcher 类执行 ldap 查询。
供参考:
http://www.codeproject.com/KB/system/QueryADwithDotNet.aspx< /a>
Use the DirectorySearcher class to preform an ldap query.
For reference:
http://www.codeproject.com/KB/system/QueryADwithDotNet.aspx
我需要一种对用户进行身份验证的方法,并检查他们是否属于特定的用户组。我通过推送用户名和密码并将“memberOf”属性加载到“搜索”实例中来完成此操作。下面的示例将显示该特定用户名的所有组。 “catch”语句将捕获错误的用户名或密码。
希望这有帮助。 (记得引用System.DirectoryServices)
I needed a method of authenticating a user and a check to see if they were in a specific user group. I did it by pushing the username and password and loading the "memberOf" property into the 'search' instance. Example below will display all the groups for that specific user name. The 'catch' statement will trap a wrong user name or password.
Hope this helps. (Remember to reference System.DirectoryServices)
我认为上面列出的大多数方法都应该有效,但我建议添加代码以确保您的代码可以“检测嵌套组成员资格中的循环循环”,如果找到,请打破您选择的脚本可能进入的任何无限循环。
I think most methods listed above should work, but i would suggest adding code to ensure that your code can "detect circular loops in nested group memberships", and if found, break any infinite loops that your script of choice could potentially get into.