0
我有一個下拉列表,我試圖用屬於Active Directory中某個組的用戶來填充。如何獲取屬於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
我已經能夠證實,該集團的確存在和組名是有效的。 感謝很多提前
你需要通過檢查開始,如果你的oresult對象爲空。如果是,那麼您的LDAP搜索過濾器工作不正常。如果不是那麼你正在尋找的屬性不在那裏。找出並讓我們知道。 – markp3rry
我已經完成了這些檢查。 也有一些是不對的: 'osearcher.Filter = 「(&(objectCategory =組)(CN = {0}))」' 我不知道是什麼objectcategory應該或是否應該有對象類。希望更有經驗的專家能幫助我。 我真的沒有這很難弄清楚我做錯了什麼。 –
我只能說經驗; (&(objectClass = person)(telephoneNumber = *),然後根據用戶搜索的內容添加一個或多個過濾器(即SN =「surname」*) )。我會先嚐試objectCategory/objectClass查詢,然後看看你是否得到了你的AD的響應,然後再試圖進一步縮小範圍。 – markp3rry