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)