I have not been able to successfully verify a user with LDAP for an ASP.NET web application. I have done so on our own network against Active Directory, but this is against a server outside of our network that is OID (Oracle Internet Directory).
Usually, I use the following code with no problem.
Dim myDirectoryEntry As New System.DirectoryServices.DirectoryEntry("LDAP://1.2.3.4:999/OU=SomeOU,DC=Something,DC=com")
myDirectoryEntry.AuthenticationType = System.DirectoryServices.AuthenticationTypes.Sealing
myDirectoryEntry.AuthenticationType = System.DirectoryServices.AuthenticationTypes.Secure
Try
myDirectoryEntry.Username = txtUserID.Text.Trim
myDirectoryEntry.Password = txtPassword.Text.Trim
Dim mySearcher As New System.DirectoryServices.DirectorySearcher(myDirectoryEntry)
mySearcher.Filter = ("(anr= " & txtUserID.Text & ")")
Dim result As System.DirectoryServices.SearchResult = mySearcher.FindOne
Catch ex As Exception
'failed log in handling
End Try
For this application, I am going against a directory outside our network and the above method fails (The requested authentication method is not supported by the server.).
I can successfully bind to the LDAP server using:
Dim serverName As String = "1.2.3.4:999"
Dim dn As String = "cn=somename,cn=users,dc=something,dc=gov"
Dim ServerCon As New LdapConnection(serverName)
ServerCon.AuthType = AuthType.Basic
Dim cred As New System.Net.NetworkCredential(dn, "password")
ServerCon.Bind(cred)
After that, I haven't been able to find a method to verify a user's log in information with their password and then pull back some information.