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.
pearlvisionAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2003

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.