• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 322
  • Last Modified:

Need specific LDAP query

The situation is this: a programmer is trying to set up an ASP page that grabs a user's name from their current session and use that to query AD to get that user's email address. So what I am looking for is the LDAP query that would pull the email address from AD based on their username, if there is one. I have seen queries to find users who are mail enabled or have an email address, but none that pulls the actual address.

Not to be a jerk, but...
Please supply only the query or a page relevant to this query. Do not link me to KB articles about LDAP or pages with LDAP syntax that are pointless or irrelevant please.  I just want to know if there is a query and how to find it. Thank you.
0
pearlvision
Asked:
pearlvision
2 Solutions
 
jss1199Commented:
Hi pearlvision,

The below code will grab the full name and email address of the user accessing the page...

        'Get the domain identity of the user hitting the site
        Dim dUser As String =
System.Security.Principal.WindowsIdentity.GetCurrent.Name
        Dim i As Integer
        'Find the backslash
        i = dUser.IndexOf("\")
        'Extract the username from the domain name
        Dim uName As String = dUser.Substring(i + 1).Trim
        'Do a directory search for the username
        Dim dSearch As DirectorySearcher = New DirectorySearcher("(anr=" & 
uName & ")")
        Dim sResult As SearchResult
        'Assign the search result
        sResult = dSearch.FindOne()
        'Assign to the variables
        Dim fullName As String = sResult.Properties("name")(0)
        userEmail = sResult.Properties("mail")(0)


Cheers!
0
 
Giuseppe "Pino" De FrancescoSenior Solution ArchitectCommented:
Hiya,
I think that this link can be useful to have a bit more: http://www.rallenhome.com/books/adcookbook/code.html

Have fun ;)

Pino
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now