|
-
Jun 21st, 2011, 03:51 PM
#1
[RESOLVED] Need to understand this, PHP connecting to LDAP
I have a php page from the previous developer that I would like to convert into a new .Net webapp so I can expand it later.
It connects to an LDAP server, loops through the properties and spits it out on the page as a table. My biggest problem is, I can't seem to get .Net to connect to the LDAP server even though I'm building the connection url following a few examples, I keep getting either a "Invalid username and password" or "Unexpected Error from COM" when I try. I've attached the PHP file here & here's the .Net code I have so far:
Code:
Friend Module LDAPModule
Friend Const g_LDAP_Password As String = "password"
Friend Const g_LDAP_Server As String = "server"
'Friend Const g_LDAPrdn As String = "cn=root"
Friend Const g_LDAP_Connection As String = "LDAP://{0}/cn=users,dc=ecop,dc=com"
Friend Function GetEmptyUsersTable() As DataTable
Dim Output As New DataTable("LDAP_Users")
With Output.Columns
.Add("UserID", GetType(String))
.Add("Password", GetType(String))
.Add("FirstName", GetType(String))
.Add("LastName", GetType(String))
.Add("EmpType", GetType(String))
.Add("PhoneNumber", GetType(String))
.Add("EmailAddress", GetType(String))
End With
Return Output
End Function
End Module
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Call BindGrid(GetAllPortalUsers())
End Sub
Private Function GetAllPortalUsers() As DataTable
Dim PortalUsers As DataTable = GetEmptyUsersTable()
Dim oSearcher As New DirectorySearcher(New DirectoryEntry(String.Format(g_LDAP_Connection, String.Empty, g_LDAP_Password, AuthenticationTypes.Anonymous)))
Dim oResults As SearchResultCollection
Dim oResult As SearchResult
'Dim RetArray As New Hashtable()
Try
oSearcher.PropertiesToLoad.Add("uid=*")
oResults = oSearcher.FindAll
Dim dr As DataRow
For Each oResult In oResults
If Not oResult.GetDirectoryEntry().Properties("cn").Value.ToString = String.Empty Then
dr = PortalUsers.NewRow
dr("UserID") = oResult.GetDirectoryEntry().Properties("uid").Value
'dr("Password") =
'dr("EmpType") =
'dr("FirstName") =
'dr("LastName") =
'dr("PhoneNumber") =
'dr("EmailAddress") =
PortalUsers.Rows.Add(dr)
dr = Nothing
'RetArray.Add(oResult.GetDirectoryEntry().Properties("uid").Value, oResult.GetDirectoryEntry().Properties("cn").Value)
End If
Next
Catch ex As Exception
Response.Write(ex.ToString & "<hr /><br />")
ErrorLabel.Text = ex.Message
ErrorLabel.Visible = True
End Try
Return PortalUsers
End Function
Private Sub BindGrid(ByVal DataSource As Object)
With UsersGridView
.DataSource = DataSource
.DataBind()
End With
End Sub
End Class
Could someone at least help me understand what the LDAP url and login process is for this LDAP server?
Thanks
Last edited by JuggaloBrotha; May 20th, 2012 at 07:02 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|