Retrieve e-mail address from Active Directory

Discussion in 'ASP .Net' started by =?Utf-8?B?bWc=?=, Feb 5, 2004.

  1. 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.
     
    =?Utf-8?B?bWc=?=, Feb 5, 2004
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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.
     
    Steve C. Orr [MVP, MCSD], Feb 5, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Federica
    Replies:
    0
    Views:
    596
    Federica
    Apr 18, 2004
  2. John Dalberg
    Replies:
    1
    Views:
    2,684
    =?Utf-8?B?U2l2YSBN?=
    Sep 19, 2005
  3. =?Utf-8?B?Qmx1ZVNreQ==?=

    Retrieve User Information from Active Directory

    =?Utf-8?B?Qmx1ZVNreQ==?=, Mar 8, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    5,139
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Mar 8, 2006
  4. mg
    Replies:
    0
    Views:
    135
  5. M
    Replies:
    2
    Views:
    255
    Teddy Biesecker
    Mar 16, 2006
Loading...

Share This Page