Have you considered using the classes in System.DirectoryServices for
accessing AD in .NET? It is much more straightforward.
Generally, when people authenticate users to AD using LDAP, they will do a
bind to AD using the DirectoryEntry class. The code might look like this:
'Imports System.DirectoryServices
'Imports System.Runtime.InteropServices
'Imports System.Globalization
Public Function AuthenticateUser(ByVal userName As String, ByVal password
As String, ByVal domain As String, ByVal server As String) As Boolean
If userName Is Nothing OrElse userName.Length = 0 Then Throw New
ArgumentNullException("userName")
If password Is Nothing OrElse password.Length = 0 Then Throw New
ArgumentNullException("password")
If domain Is Nothing OrElse domain.Length = 0 Then Throw New
ArgumentNullException("domain")
If server Is Nothing OrElse server.Length = 0 Then Throw New
ArgumentNullException("server")
Dim ntLogonName As String
Dim entry As DirectoryEntry
ntLogonName = String.Format(CultureInfo.InvariantCulture,
"{0}\{1}", domain, userName)
entry = New DirectoryEntry( _
String.Format( _
CultureInfo.InvariantCulture, _
"LDAP://{0}/rootDSE", server), _
ntLogonName, _
password, _
AuthenticationTypes.Secure _
)
Try
Dim bindTest As Object
bindTest entry.NativeObject 'this forces the bind to AD
Return True
Catch ex As COMException
If ex.ErrorCode = &H8007052E Then 'COM error code for "Bad
username or password"
Return False
Else
Throw 'if the problem wasn't bad credentials, then we there is
something else wrong here
End If
Finally
entry.Dispose()
End Try
End Function
You need to add a reference to System.DirectoryServices as well.
The DirectorySearcher class is also much more straightforward to use for
searching AD.
HTH,
Joe K.
> Hello
>
[quoted text clipped - 57 lines]
> Thank you
> Jon