[英]How do I get the users that belong to a group in Active Directory?
I have a dropdownlist that I am trying to fill with users that belong to a certain group in Active Directory. 我有一个下拉列表,我试图填写属于Active Directory中某个组的用户。
The group name is OverRiders and 8 people are members of this group. 组名是OverRiders,8人是该组的成员。 More members could be added. 可以添加更多成员。
I have the following dropdown but I run the code, the dropdown is blank. 我有以下下拉列表,但我运行代码,下拉列表是空白。
What am I doing wrong? 我究竟做错了什么?
Please see code: 请看代码:
Private Sub FillDropdown()
Dim oroot As DirectoryEntry = New DirectoryEntry("LDAP://CN=OverRiders,OU=Departments,DC=domain,DC=com")
Dim osearcher As DirectorySearcher = New DirectorySearcher(oroot)
Dim oresult As SearchResultCollection
Dim result As SearchResult
Dim list As New List(Of String)
osearcher.Filter = "(&(objectCategory=group)(cn={0}))"
' search filter; only display emp with firstname / lastname pair
osearcher.PropertiesToLoad.Add("name") ' member
oresult = osearcher.FindAll()
For Each result In oresult
If Not result.GetDirectoryEntry.Properties("name").Value Is Nothing Then
list.Add(result.GetDirectoryEntry.Properties("name").Value.ToString())
Call list.Sort()
End If
Next
emplist.DataSource = list
emplist.DataBind()
End Sub
I have been able to confirm that the group does exist and the group name is valid. 我已经能够确认该组确实存在且组名称有效。 Thanks a lot in advance 非常感谢提前
Changed: 更改:
Dim oroot As DirectoryEntry = New DirectoryEntry("LDAP://CN=OverRiders,OU=Departments,DC=domain,DC=com")
to 至
Dim oroot As DirectoryEntry = New DirectoryEntry("LDAP://DC=domain,DC=com")
and this: 和这个:
osearcher.Filter = "(&(objectCategory=group)(cn={0}))"
to this: 对此:
osearcher.Filter = "(&(objectCategory=user)(memberOf=CN=overRiders,OU=Departments,DC=domain,DC=com))"
Everything else remain unchanged. 其他一切都保持不变。
Hope it helps someone else. 希望它可以帮助别人。
I know this is an old question, but this is what worked for me in a similar situation: 我知道这是一个老问题,但这对我来说在类似的情况下是有用的:
Dim UsersInGroup As New Collection()
Dim de As New DirectoryEntry("LDAP://[Domain]")
Dim MemberSearcher As New DirectorySearcher
With MemberSearcher
.SearchRoot = de
.Filter = "(&(ObjectClass=Group)(CN=" & Group & "))"
.PropertiesToLoad.Add("Member")
End With
Dim mySearchResults As SearchResult = MemberSearcher.FindOne()
For Each User In mySearchResults.Properties("Member")
UsersInGroup.Add(User)
Next
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.