Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AD and ASP Help

Status
Not open for further replies.

wantagofast

Technical User
Jun 19, 2002
47
US
I want to first state that I am not a programmer by any means. With that said, here is my problem.

I have a intranet site with an ASP page that I would like to pull the user name from AD so when a user opens their web browser, the ASP page will say something like "Welcome John Smith!".

I know this is a simple problem, but I can't find any threads on this topic.

I am running IIS6 with authentication turned on.

Thanks in advance.

Matt
 
You may need to install a third-party component that can access Active Directory. Google Persits software and look at their AspUser component.
 
If it is for your intranet then you could just turn off annonymous access and then read the username from Request.ServerVariables("LOGON_USER") and then get the user's proper name from the AD via ADSI.
 
Sheco wrote:

If it is for your intranet then you could just turn off annonymous access and then read the username from Request.ServerVariables("LOGON_USER") and

I was able to pull "domain\username"

"...then get the user's proper name from the AD via ADSI."

How? What code would I use?

Thanks.
 
Sheco,

I reviewed the link and tried many different ways to "pull" the "common name" but I can't seem to retrieve the information.

Here is the code:

Set Odse = GetObject( "LDAP//DC=Users,DC=DomainName,DC=com")

On Error Resume Next
Set objUser = GetObject _
("LDAP://cn=username,ou=users,dc=domainname,dc=com")
objUser.GetInfo

strUserPrincipalName = objUser.Get("userPrincipalName")
strSAMAccountName = objUser.Get("sAMAccountName")
strUserWorkstations = objUser.Get("userWorkstations")

Set objDomain = GetObject("LDAP://dc=domainname,dc=com")
objDomain.GetInfoEx Array("dc"), 0
strDC = objDomain.Get("dc")

WScript.echo "userPrincipalName: " & strUserPrincipalName
WScript.echo "sAMAccountName: " & strSAMAccountName
WScript.echo "UserWorkstations: " & strUserWorkstations
WScript.echo "dc: " & strDC

What am I doing wrong?

Thanks for your assistance.
 
What errors do you see?

WScript.echo? How about Response.Write instead?

 
All I did was cut and paste the code from the site you gave me. I changed the domain name and OU but that's about it. The code just comes up in the web browser.

I will change it to read Response.Write instead.
 
Yeah that site has VB/VBScript code but it looks like the focus is more on creating script files for network administration than ASP...

... so there are little things like the .Echo that will work fine for running the script as a user logged into the computer but that don't quite translate to web applications. Another thing might be the use of Server.CreateObject instead of plain CreateObject.
 
Can anyone else help me? I really need some help on this.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top