Dim initLDAPPath As String = "CN=Users,DC=poc,DC=com"
Dim initLDAPServer As String = "192.168.103.22"
Dim initShortDomainName As String = "poc.com"
Dim strErrMsg As String
Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim DomainAndUsername As String = ""
Dim strCommu As String
Dim flgLogin As Boolean = False
strCommu = "LDAP://" & initLDAPServer & "/" & initLDAPPath
DomainAndUsername = initShortDomainName & "\" & txtUser.Text
Dim entry As New DirectoryEntry(strCommu, DomainAndUsername, txtPwd.Text)
Dim obj As Object
Try
obj = entry.NativeObject
Dim search As New DirectorySearcher(entry)
Dim result As SearchResult
search.Filter = "(SAMAccountName=" + txtUser.Text + ")"
search.PropertiesToLoad.Add("cn")
result = search.FindOne()
If result Is Nothing Then
flgLogin = False
strErrMsg = "Please check user/password"
Else
flgLogin = True
End If
Catch ex As Exception
flgLogin = False
strErrMsg = "Please check user/password"
End Try
If flgLogin = True Then
Me.lbDisplay.Text = "Welcome " & txtUser.Text
Response.Redirect("Index.aspx")
Else
Me.lbDisplay.Text = strErrMsg
End If