Results 1 to 16 of 16

Thread: [RESOLVED] Need to understand this, PHP connecting to LDAP

Threaded View

  1. #1

    Thread Starter
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Resolved [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.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width