get user details from Active Directory

Discussion in 'ASP .Net' started by =?Utf-8?B?RGFuIE5hc2g=?=, Oct 11, 2004.

  1. 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
     
    =?Utf-8?B?RGFuIE5hc2g=?=, Oct 11, 2004
    #1
    1. Advertising

  2. hi nash,
    you have it all here
    http://www.c-sharpcorner.com/DirectoryServices.asp
    HTH
    srini

    "Dan Nash" wrote:

    > 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
     
    =?Utf-8?B?c3Jpbmk=?=, Oct 11, 2004
    #2
    1. Advertising

  3. =?Utf-8?B?RGFuIE5hc2g=?=

    Mike Newton Guest

    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.




    Dan Nash wrote:
    > 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
     
    Mike Newton, Oct 11, 2004
    #3
  4. 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

    "Dan Nash" wrote:

    > 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
     
    =?Utf-8?B?RGFuIE5hc2g=?=, Oct 11, 2004
    #4
  5. =?Utf-8?B?RGFuIE5hc2g=?=

    Mike Newton Guest

    You need to add System.DirectoryServices as a reference.



    Dan Nash wrote:
    > 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
    >
    > "Dan Nash" wrote:
    >
    >
    >>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
     
    Mike Newton, Oct 11, 2004
    #5
  6. =?Utf-8?B?RGFuIE5hc2g=?=

    Eddy Jawed

    Joined:
    Jul 28, 2009
    Messages:
    2
    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
     
    Eddy Jawed, Jun 2, 2010
    #6
  7. =?Utf-8?B?RGFuIE5hc2g=?=

    Eddy Jawed

    Joined:
    Jul 28, 2009
    Messages:
    2
    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.
     
    Eddy Jawed, Jun 2, 2010
    #7
    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. A.M
    Replies:
    0
    Views:
    636
  2. McGeeky
    Replies:
    1
    Views:
    554
    Patrick.O.Ige
    Feb 17, 2006
  3. =?Utf-8?B?Sm9l?=

    Show Details/Hide Details link button

    =?Utf-8?B?Sm9l?=, Mar 13, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    930
    dkode
    Mar 13, 2006
  4. ejcosta
    Replies:
    2
    Views:
    885
    Eurico Costa
    Oct 8, 2004
  5. A Lake

    Get user details ASP/LDAP/WINNT

    A Lake, Mar 11, 2005, in forum: ASP General
    Replies:
    2
    Views:
    284
    A Lake
    Mar 11, 2005
Loading...

Share This Page