get user details from Active Directory

G

Guest

Hi

I've got the Username of the logged in user and domain with
Page.User.Identity.Name. It comes in as "domain\user".

Now, I want to query AD to get the users Firstname and Email address. Can
anyone point me in the direction of an article?

Cheers


Dan
 
M

Mike Newton

Use an LDAP search.

Here's the RFC: http://www.faqs.org/rfcs/rfc2254.html

Here are a couple of articles on how to use it:
http://www.wwwcoder.com/main/parentid/272/site/1694/68/default.aspx
http://www.codeproject.com/csharp/ADTester.asp
http://www.codeproject.com/aspnet/adsi1.asp

This one isn't as detailed:
http://www.codeproject.com/vb/net/LDAP_Using_VBnet.asp

Just remember that your logical operators for the filter are in prefix
notation. A search would go something like (&(CN='Dog')(Name='Yada'))
for AND operations, (|...) for OR operations.

The particular AD property that has the user name, I've found, is
sAMAccountName. This may or may not be the same for you. You'll have
to split off the domain name in any case.
 
G

Guest

Thanks guys - all very helpful.

However, I'm now trying to get it working (VC#). Problem I'm getting is it
doesn't seem to recognise the System.DirectoryServices namespace?

It's not in the Intellisense lists, and if I just type it, it says it can't
find it. Any ideas?

Cheers

Dan
 
Joined
Jul 28, 2009
Messages
2
Reaction score
0
This is my technique listing e-mail addresses

Hi guys,

Here is some simple code that if you pass the first and surname of the person, it will find ALL e-mails of people with that name, not just the first one.


Imports System.Diagnostics.Debug
Imports System.DirectoryServices

Public Function GetEmailAddress(ByVal FirstName As String, ByVal LastName As String)

Dim X As Integer
Dim search As DirectorySearcher = New DirectorySearcher()
search.Filter = "(&(givenName=" + FirstName + ")(sn=" + LastName+ "))"

Dim res As SearchResultCollection = search.FindAll()

For Each ItemRes As SearchResult In res

WriteLine(ItemRes.Properties("mail")(0).ToString())
Next

End Function


Thanks

Eddy
 
Joined
Jul 28, 2009
Messages
2
Reaction score
0
To get other object items.

Also if you want to modify it to get other items belonging to the person in question, then simply call on another property.

I used "mail" property in ItemRes.Properties("mail")(0).ToString())

But there are other properties for given name, domain etc, whatever it is you need. Just play around with it for a bit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top