R
Rosanne Rohana
I'm trying for return user info (first name, last name, etc.) from a
Netscape 4.16 LDAP server using the System.DirectoryServices. I'm able to
get authenticated successfully, but when I attempt to return search results
nothing ever comes back. For example, "result = searcher.FindOne()" always
returns "nothing" and the "searcher.FindAll" collection always return a
count of zero. I've tried many different filters and PropertiesToLoad. Some
help would be greatly appreciated. Some test code is below.
Public Sub testLDAP()
Dim HostIPName = "thedomain.com"
Dim HostIPPort As String = "389"
Dim userID = "testuser"
Dim Password As String = "passw"
Dim orgUnit As String = "ou=Employees, ou=People"
Dim organization As String = "o=MyCompany.com"
Dim dn As String = "uid=" + userID + "," + orgUnit + "," +
organization
Dim entry As New DirectoryEntry("LDAP://" & HostIPName & ":" &
HostIPPort, dn, Password, AuthenticationTypes.None)
Dim ValidateUser As Boolean = False
'This will Authenticate
Dim native As Object = entry.NativeObject
ValidateUser = True
MsgBox("ValidateUser = True")
Dim searcher As New DirectorySearcher(entry)
With searcher
.Filter = "(&(uid=" & userID & "))"
.PropertiesToLoad.Add("givenname") 'First
.PropertiesToLoad.Add("sn") 'Last
.PropertiesToLoad.Add("cn") 'Full
End With
Dim result As System.DirectoryServices.SearchResult
Dim tempEntry As DirectoryEntry
result = searcher.FindOne()
MsgBox(result)
'try FindAll ???
For Each result In searcher.FindAll
MsgBox(result.ToString)
tempEntry = result.GetDirectoryEntry
MsgBox(tempEntry.Password)
MsgBox(tempEntry.Name)
MsgBox(tempEntry.Path)
Next
End Sub
Netscape 4.16 LDAP server using the System.DirectoryServices. I'm able to
get authenticated successfully, but when I attempt to return search results
nothing ever comes back. For example, "result = searcher.FindOne()" always
returns "nothing" and the "searcher.FindAll" collection always return a
count of zero. I've tried many different filters and PropertiesToLoad. Some
help would be greatly appreciated. Some test code is below.
Public Sub testLDAP()
Dim HostIPName = "thedomain.com"
Dim HostIPPort As String = "389"
Dim userID = "testuser"
Dim Password As String = "passw"
Dim orgUnit As String = "ou=Employees, ou=People"
Dim organization As String = "o=MyCompany.com"
Dim dn As String = "uid=" + userID + "," + orgUnit + "," +
organization
Dim entry As New DirectoryEntry("LDAP://" & HostIPName & ":" &
HostIPPort, dn, Password, AuthenticationTypes.None)
Dim ValidateUser As Boolean = False
'This will Authenticate
Dim native As Object = entry.NativeObject
ValidateUser = True
MsgBox("ValidateUser = True")
Dim searcher As New DirectorySearcher(entry)
With searcher
.Filter = "(&(uid=" & userID & "))"
.PropertiesToLoad.Add("givenname") 'First
.PropertiesToLoad.Add("sn") 'Last
.PropertiesToLoad.Add("cn") 'Full
End With
Dim result As System.DirectoryServices.SearchResult
Dim tempEntry As DirectoryEntry
result = searcher.FindOne()
MsgBox(result)
'try FindAll ???
For Each result In searcher.FindAll
MsgBox(result.ToString)
tempEntry = result.GetDirectoryEntry
MsgBox(tempEntry.Password)
MsgBox(tempEntry.Name)
MsgBox(tempEntry.Path)
Next
End Sub