0

我有一个下拉列表,我试图用属于 Active Directory 中某个组的用户来填充。

组名为 OverRiders,8 人是该组的成员。可以添加更多成员。

我有以下下拉列表,但我运行代码,下拉列表为空白。

我究竟做错了什么?

请看代码:

        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

我已经能够确认该组确实存在并且组名有效。非常感谢提前

4

2 回答 2

2

改变:

Dim oroot As DirectoryEntry = New DirectoryEntry("LDAP://CN=OverRiders,OU=Departments,DC=domain,DC=com")

Dim oroot As DirectoryEntry = New DirectoryEntry("LDAP://DC=domain,DC=com")

还有这个:

osearcher.Filter = "(&(objectCategory=group)(cn={0}))"

对此:

osearcher.Filter = "(&(objectCategory=user)(memberOf=CN=overRiders,OU=Departments,DC=domain,DC=com)‌​)"

其他一切都保持不变。

希望它可以帮助别人。

于 2013-02-05T17:08:45.280 回答
1

我知道这是一个老问题,但在类似情况下这对我有用:

    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
于 2016-10-09T01:48:51.980 回答