Hi All,
I am trying to do Forms Authentication against Active Directory and have got everything working expect for that I can authenticate with any domain information. Please find the code and flow below and let me know what could be wrong.
Step 1. User is prompted for credentials - UserName, Password, Domain
Step 2. Users submits the page.
Step 3. Execute code below
Dim adPath As String = "LDAP:// OUR DOMAIN NAME")
Dim domainAndUsername As String = domain & "\" & username
Dim entry As DirectoryEntry = New DirectoryEntry(adPath, domainAndUsername, pwd, AuthenticationTypes.Secure)
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.
adPath = result.Path
_filterAttribute = CType(result.Properties("cn")(0), String)
Catch ex As Exception
Throw New Exception("Error authenticating user. " & ex.Message)
End Try
Now user is still authenticated though the user has entered correct username and password and an invalid Domain Name. Don't know what is causing this?
Thanks and Regards,
Parag