Results 1 to 2 of 2

Thread: [RESOLVED] Active Directory Integration

  1. #1
    New Member
    Join Date
    Jul 12
    Posts
    2

    Resolved [RESOLVED] Active Directory Integration

    Hello Everyone. I'm glad to see there is another active VB community besides Microsofts.

    I'm working with Visual Web Developer 2010 Express and I'm a VB coder. With that said I need some help with a web application that reads and modifies information in two location. Some information is from AD and the other is from a SQL db.

    I took a stock Web Application that came with some predefined pages, one being a login page, and modified the login sequence to use AD for authentication.

    Now I'm needing to do a few more things. I know how to read information from a SQL database but not from ActiveDirectory.

    I want to take the currently logged in user and pull some information from AD: first name, last name, middle name, address, department, phone number, email address, etc.

    I'm lost on how to read/write to AD.

    Thanks for any help in advance. If anyone wants to see what I did for the AD login section, I will be happy to post my code.

  2. #2
    New Member
    Join Date
    Jul 12
    Posts
    2

    Re: Active Directory Integration

    For anyone that could use this in the future. Here is the code that I have used and tested.

    Code:
    Private Function GetADObject(ByVal ojbectparam As String, ByVal ADUser As String) As String
            Dim ADOValue As String = ""
            Dim dE As New DirectoryEntry("LDAP://DC=xxx,DC=xxx")
            Dim dSearch = New DirectorySearcher(dE)
            dSearch.Filter = "(samaccountname=" & ADUser & ")"
    
            dSearch.PropertiesToLoad.Add(ojbectparam)
            Dim sr As SearchResult = dSearch.FindOne
            Dim x As System.DirectoryServices.DirectoryEntry = sr.GetDirectoryEntry()
    
            If Not x.Properties(ojbectparam).Value Is Nothing Then
                ADOValue = x.Properties(ojbectparam).Value.ToString()
            End If
    
            Return ADOValue
        End Function
    That is the function that I called to return the specific value I was looking for.
    Here is how to call the above function and use the current ASP.NET application logged in user. This particular call asks for the users last name.

    Code:
    TextBox1.Text = GetADObject("sn", Membership.GetUser().ToString)

Posting Permissions

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