Retrieve e-mail address from Active Directory

G

Guest

Can someone give me C# code that will connect me to Active Directory, let me give Active Directory a user's name and retrieve his/her e-mail address. I need this for a WebForm.
 
S

Steve C. Orr [MVP, MCSD]

This code should get you the user's full name.
With a little tinkering I bet you can also get the email address.
(also set <identity impersonate="true"/> in your web.config)

string Domain_Slash_User = Context.User.Identity.Name;
Domain_Slash_Machine = Domain_Slash_Machine.Replace(@"\",
@"/");
string queryString = @"WinNT://" + Domain_Slash_Machine;

DirectoryEntry obDirEntry = new DirectoryEntry
(queryString);
System.DirectoryServices.PropertyCollection coll =
obDirEntry.Properties;

object obVal = coll["FullName"].Value;
_User = obVal.ToString();

Session.Add("UserFullName", _User);

--
I hope this helps,
Steve C. Orr, MCSD
http://Steve.Orr.net


mg said:
Can someone give me C# code that will connect me to Active Directory, let
me give Active Directory a user's name and retrieve his/her e-mail address.
I need this for a WebForm.
 

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,053
Latest member
BrodieSola

Latest Threads

Top