Please help...want to display full name from AD on my intranet

Discussion in 'ASP .Net' started by wantagofast@yahoo.com, Oct 21, 2005.

  1. Guest

    Hello all! I have been searching for what seems like days now on how
    to have my users full name (ie. John Smith) to appear on my intranet
    but can't seem to be able to find the correct asp code. I have the
    users authenticate by IIS via AD. I found some code to pull the user
    name but I really would like to pull the users full name.

    Would someone be so kind as to share with me the code to do just that.
    I need the complete code as I am not a programmer and can get very
    confused. I would really appreciate it. Otherwise, I may just loose
    my mind!

    Thanks so much in advance!

    Matt
     
    , Oct 21, 2005
    #1
    1. Advertising

  2. public string GetUserFullnameFromAccount(string username)
    {
    DirectoryEntry entryRoot = new DirectoryEntry("LDAP://RootDSE");
    string domain = entryRoot.Properties["defaultNamingContext"][0] as
    string;
    DirectoryEntry searchRoot = new
    DirectoryEntry(@"LDAP://"+domain,<ADUserUsername>,<ADUserPassword>);
    DirectorySearcher search = new DirectorySearcher(searchRoot);
    search.Filter =
    "(&(objectClass=user)(objectCategory=person)(sAMAccountName="+username+"))";
    search.PropertiesToLoad.Add("samaccountname");
    search.PropertiesToLoad.Add("cn");
    search.PropertiesToLoad.Add("displayName");

    SearchResult result = search.FindOne();

    return result.GetDirectoryEntry().Properties["displayName"].Value as
    string;
    }

    where <ADUserUsername> is the username of a user with search access in
    AD
    and <ADUserPassword> the password of that user.

    The code takes the current domain.


    Use it like this : GetUserFullnameFromAccount("username");
     
    Tasos Vogiatzoglou, Oct 21, 2005
    #2
    1. Advertising

  3. Try Tasos advice and hat should do the trick.
    If you need more help POST it
    Pstrick
    <> wrote in message
    news:...
    > Hello all! I have been searching for what seems like days now on how
    > to have my users full name (ie. John Smith) to appear on my intranet
    > but can't seem to be able to find the correct asp code. I have the
    > users authenticate by IIS via AD. I found some code to pull the user
    > name but I really would like to pull the users full name.
    >
    > Would someone be so kind as to share with me the code to do just that.
    > I need the complete code as I am not a programmer and can get very
    > confused. I would really appreciate it. Otherwise, I may just loose
    > my mind!
    >
    > Thanks so much in advance!
    >
    > Matt
    >
     
    Patrick.O.Ige, Oct 21, 2005
    #3
  4. Guest

    Thanks for your assistance! But I am a little confused. I cut and
    pasted the code into my asp page and now I get this error:

    Microsoft VBScript compilation error '800a0401'

    Expected end of statement

    /test.asp, line 13

    public string GetUserFullnameFromAccount(string username)

    I pasted the code in between the two "<% %>, I think this is correct?
    Right?

    Also...were it reads "<ADUserUsername> is the username of a with search
    access", do I replace it with someone who has admin access to AD? and
    does it have to read like this <admin> or just "admin"?

    Use it like this : GetUserFullnameFromAccount("username"); - I'm not
    sure what you mean for me to do with this line.

    Thanks again for your patiences and assistance.

    Matt
     
    , Oct 21, 2005
    #4
  5. Matt:

    No, only the call, GetUserFullnameFromAccount("username"), should be between
    the "<% %>" tag.

    The other should be declared either in your vb code or included as vbscript.

    Venki

    "" wrote:

    > Thanks for your assistance! But I am a little confused. I cut and
    > pasted the code into my asp page and now I get this error:
    >
    > Microsoft VBScript compilation error '800a0401'
    >
    > Expected end of statement
    >
    > /test.asp, line 13
    >
    > public string GetUserFullnameFromAccount(string username)
    >
    > I pasted the code in between the two "<% %>, I think this is correct?
    > Right?
    >
    > Also...were it reads "<ADUserUsername> is the username of a with search
    > access", do I replace it with someone who has admin access to AD? and
    > does it have to read like this <admin> or just "admin"?
    >
    > Use it like this : GetUserFullnameFromAccount("username"); - I'm not
    > sure what you mean for me to do with this line.
    >
    > Thanks again for your patiences and assistance.
    >
    > Matt
    >
    >
     
    =?Utf-8?B?dnZlbms=?=, Oct 21, 2005
    #5
  6. Guest

    Thanks Venki. But I still can't get the script to work correctly.
    Could someone please cut and paste the exact code for the ASP page.

    Thanks again.

    Matt
     
    , Oct 23, 2005
    #6
  7. Here comes a late answer :)

    This is CSharp code... From the error message you are posting I suspect
    that you try to use the script inside an old-fashioned ASP page,
    something that will never work.

    You need an ASP.NET page in CSharp or put this in an assembly that you
    will call from your page ...

    the ADUserUsername and ADUserPassword are the username/password of a
    user with SEARCH rights in the Active Directory Catalog because ASPNET
    default user does not have this kind of access.
     
    Tasos Vogiatzoglou, Oct 25, 2005
    #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. www.cuden.com
    Replies:
    1
    Views:
    1,080
    raavi
    Jan 16, 2006
  2. KK
    Replies:
    2
    Views:
    596
    Big Brian
    Oct 14, 2003
  3. Nikron
    Replies:
    6
    Views:
    17,332
    Mark Rae
    May 31, 2006
  4. MOHR
    Replies:
    0
    Views:
    220
  5. Jack-2
    Replies:
    3
    Views:
    273
    Jack-2
    Dec 24, 2003
Loading...

Share This Page