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

W

wantagofast

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
 
T

Tasos Vogiatzoglou

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");
 
P

Patrick.O.Ige

Try Tasos advice and hat should do the trick.
If you need more help POST it
Pstrick
 
W

wantagofast

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
 
G

Guest

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
 
W

wantagofast

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
 
T

Tasos Vogiatzoglou

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.
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top