C
Chris Davoli
Environment: Win XP, VS2003, Active Directory
I'm trying to use LDAP to authenticate users. I used article
http://support.microsoft.com/?id=326340
How to authenticate against the Active Directory by using forms
authentication and Visual Basic .NET, but am having a COM interop error when
I do the IsAuthenticated try to create an object entry.NativeObject ie; Dim
obj As Object = entry.NativeObject
The COM interop error is <error: an exception of type:
{System.Runtime.InteropServices.COMException} occurred>
I'm thinking that there is some kind of COM component that is either not
registered, or not there.
Can anyone help me?
Here is the code:
Public Function IsAuthenticated(ByVal domain As String, ByVal
username As String, ByVal pwd As String) As Boolean
Dim domainAndUsername As String = domain & "\" & username
Dim entry As DirectoryEntry = New DirectoryEntry(_path,
domainAndUsername, pwd)
Try
'Bind to the native AdsObject to force authentication.
Dim obj As Object = entry.NativeObject
Dim search As DirectorySearcher = New DirectorySearcher(entry)
search.Filter = "(SAMAccountName=" & username & ")"
search.PropertiesToLoad.Add("cn")
Dim result As SearchResult = search.FindOne()
If (result Is Nothing) Then
Return False
End If
'Update the new path to the user in the directory.
_path = result.Path
_filterAttribute = CType(result.Properties("cn")(0), String)
Catch ex As Exception
Throw New Exception("Error authenticating user. " &
ex.Message)
End Try
Return True
End Function
I'm trying to use LDAP to authenticate users. I used article
http://support.microsoft.com/?id=326340
How to authenticate against the Active Directory by using forms
authentication and Visual Basic .NET, but am having a COM interop error when
I do the IsAuthenticated try to create an object entry.NativeObject ie; Dim
obj As Object = entry.NativeObject
The COM interop error is <error: an exception of type:
{System.Runtime.InteropServices.COMException} occurred>
I'm thinking that there is some kind of COM component that is either not
registered, or not there.
Can anyone help me?
Here is the code:
Public Function IsAuthenticated(ByVal domain As String, ByVal
username As String, ByVal pwd As String) As Boolean
Dim domainAndUsername As String = domain & "\" & username
Dim entry As DirectoryEntry = New DirectoryEntry(_path,
domainAndUsername, pwd)
Try
'Bind to the native AdsObject to force authentication.
Dim obj As Object = entry.NativeObject
Dim search As DirectorySearcher = New DirectorySearcher(entry)
search.Filter = "(SAMAccountName=" & username & ")"
search.PropertiesToLoad.Add("cn")
Dim result As SearchResult = search.FindOne()
If (result Is Nothing) Then
Return False
End If
'Update the new path to the user in the directory.
_path = result.Path
_filterAttribute = CType(result.Properties("cn")(0), String)
Catch ex As Exception
Throw New Exception("Error authenticating user. " &
ex.Message)
End Try
Return True
End Function