I have created Login.aspx Page On Click of Login Button.I invoke the code as follows
================================================== ====
Dim adPath As String = "LDAP://172.21.1.19" 'Path to your LDAP directory server
Dim adAuth As New Authentication.FormsAuth.LDapAuthentication(adPath )
Try
If (True = adAuth.IsAuthenticated(txtDomain.Text, txtUsername.Text, txtPassword.Text)) Then
Dim groups As String = adAuth.GetGroups()
'Create the ticket, and add the groups.
Dim isCookiePersistent As Boolean = chkPersist.Checked
Dim authTicket As FormsAuthenticationTicket = New FormsAuthenticationTicket(1, _
txtUsername.Text, DateTime.Now, DateTime.Now.AddMinutes(60), isCookiePersistent, groups)
'Encrypt the ticket.
Dim encryptedTicket As String = FormsAuthentication.Encrypt(authTicket)
'Create a cookie, and then add the encrypted ticket to the cookie as data.
Dim authCookie As HttpCookie = New HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket)
If (isCookiePersistent = True) Then
authCookie.Expires = authTicket.Expiration
End If
'Add the cookie to the outgoing cookies collection.
Response.Cookies.Add(authCookie)
'You can redirect now.
Response.Redirect(FormsAuthentication.GetRedirectU rl(txtUsername.Text, False))
Else
errorLabel.Text = "Authentication did not succeed. Check user name and password."
End If
Catch ex As Exception
errorLabel.Text = "Error authenticating. " & ex.Message
End Try
End Sub
================================================== ========I have set LDAP Path to my Server IP Address
Now In IsAuthenticated Method I am calling the code as follows
======================================
Dim domainAndUsername As String = domain & "\" & username
'Dim domainAndUserName As String = username
Dim entry As DirectoryEntry = New DirectoryEntry(_path, 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.
_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
=================================
But on the following line i am getting error called "The server is not operational"
Dim entry As DirectoryEntry = New DirectoryEntry(_path, domainAndUsername, pwd, AuthenticationTypes.Secure)
Any solution on this problem will be appreciated
Thanks in Advance