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.LDapA uthentication(a dPath)
Try
If (True = adAuth.IsAuthen ticated(txtDoma in.Text, txtUsername.Tex t, txtPassword.Tex t)) Then
Dim groups As String = adAuth.GetGroup s()
'Create the ticket, and add the groups.
Dim isCookiePersist ent As Boolean = chkPersist.Chec ked
Dim authTicket As FormsAuthentica tionTicket = New FormsAuthentica tionTicket(1, _
txtUsername.Tex t, DateTime.Now, DateTime.Now.Ad dMinutes(60), isCookiePersist ent, groups)
'Encrypt the ticket.
Dim encryptedTicket As String = FormsAuthentica tion.Encrypt(au thTicket)
'Create a cookie, and then add the encrypted ticket to the cookie as data.
Dim authCookie As HttpCookie = New HttpCookie(Form sAuthentication .FormsCookieNam e, encryptedTicket )
If (isCookiePersis tent = True) Then
authCookie.Expi res = authTicket.Expi ration
End If
'Add the cookie to the outgoing cookies collection.
Response.Cookie s.Add(authCooki e)
'You can redirect now.
Response.Redire ct(FormsAuthent ication.GetRedi rectUrl(txtUser name.Text, False))
Else
errorLabel.Text = "Authentica tion 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 domainAndUserna me As String = domain & "\" & username
'Dim domainAndUserNa me As String = username
Dim entry As DirectoryEntry = New DirectoryEntry( _path, domainAndUserna me, pwd, AuthenticationT ypes.Secure)
Try
'Bind to the native AdsObject to force authentication.
Dim obj As Object = entry.NativeObj ect
Dim search As DirectorySearch er = New DirectorySearch er(entry)
search.Filter = "(SAMAccountNam e=" & username & ")"
search.Properti esToLoad.Add("c n")
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
_filterAttribut e = CType(result.Pr operties("cn")( 0), String)
Catch ex As Exception
Throw New Exception("Erro r 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, domainAndUserna me, pwd, AuthenticationT ypes.Secure)
Any solution on this problem will be appreciated
Thanks in Advance
=============== =============== =============== =========
Dim adPath As String = "LDAP://172.21.1.19" 'Path to your LDAP directory server
Dim adAuth As New Authentication. FormsAuth.LDapA uthentication(a dPath)
Try
If (True = adAuth.IsAuthen ticated(txtDoma in.Text, txtUsername.Tex t, txtPassword.Tex t)) Then
Dim groups As String = adAuth.GetGroup s()
'Create the ticket, and add the groups.
Dim isCookiePersist ent As Boolean = chkPersist.Chec ked
Dim authTicket As FormsAuthentica tionTicket = New FormsAuthentica tionTicket(1, _
txtUsername.Tex t, DateTime.Now, DateTime.Now.Ad dMinutes(60), isCookiePersist ent, groups)
'Encrypt the ticket.
Dim encryptedTicket As String = FormsAuthentica tion.Encrypt(au thTicket)
'Create a cookie, and then add the encrypted ticket to the cookie as data.
Dim authCookie As HttpCookie = New HttpCookie(Form sAuthentication .FormsCookieNam e, encryptedTicket )
If (isCookiePersis tent = True) Then
authCookie.Expi res = authTicket.Expi ration
End If
'Add the cookie to the outgoing cookies collection.
Response.Cookie s.Add(authCooki e)
'You can redirect now.
Response.Redire ct(FormsAuthent ication.GetRedi rectUrl(txtUser name.Text, False))
Else
errorLabel.Text = "Authentica tion 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 domainAndUserna me As String = domain & "\" & username
'Dim domainAndUserNa me As String = username
Dim entry As DirectoryEntry = New DirectoryEntry( _path, domainAndUserna me, pwd, AuthenticationT ypes.Secure)
Try
'Bind to the native AdsObject to force authentication.
Dim obj As Object = entry.NativeObj ect
Dim search As DirectorySearch er = New DirectorySearch er(entry)
search.Filter = "(SAMAccountNam e=" & username & ")"
search.Properti esToLoad.Add("c n")
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
_filterAttribut e = CType(result.Pr operties("cn")( 0), String)
Catch ex As Exception
Throw New Exception("Erro r 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, domainAndUserna me, pwd, AuthenticationT ypes.Secure)
Any solution on this problem will be appreciated
Thanks in Advance
Comment