We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Need specific LDAP query

pearlvision
pearlvision asked
on
Medium Priority
359 Views
Last Modified: 2010-04-18
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.
Comment
Watch Question

Commented:
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!

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Giuseppe 'Pino' De FrancescoSnr. Solutions Architect
CERTIFIED EXPERT
Commented:
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
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.