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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Active Directory using ASP

Status
Not open for further replies.

ACuba10

Programmer
Jul 25, 2006
14
US
does anyone know what the code would look like if i wanted to pull the First and Last Names out by using the LoginId?? Please any help would be greatly appreciated. thanks.
 
Hmm. I tried the search tab above and searched on "Active Directory":
Hundreds of records matched your query of active directory. Outputting records 1 to 20.

The first few look like they may outline what you need.

-T

 
one option is to hack kerberos(to not have to put in a user id/password)...but is too touchy...you may be interested in using this little script I find handy..

simply replace user id and password w/ yours...should be all you need...good luck
Code:
<%
  Function getLogon()
   getLogon = (Mid(Request.ServerVariables("LOGON_USER"), _
               InStrRev(Request.ServerVariables("LOGON_USER"), "\") + 1))
  End Function


  Sub getUser(sLogon)
   Set oRootDSE = GetObject("LDAP://RootDSE")  
   sDomain = oRootDSE.Get("defaultNamingContext") 
 
   Set oConn = CreateObject("ADODB.Connection")
   oConn.Open ("Data Source=Active Directory Provider;Provider=ADsDSOObject;User ID=domain\test_acct;password=1234567890;")
   Set oRs = oConn.Execute("SELECT sn, givenName " & _
                           "FROM 'LDAP://" & sDomain & "' " & _
                           "WHERE samaccountname='" & sLogon & "'")
   If Not oRs.EOF Then
    If Not isNull(oRs("sn")) AND Not isNull(oRs("givenName")) Then    
     sLastName = oRs("sn")
     sFirstName = oRs("givenName")


     Response.Write "<b>Logon:</b>" & sLogon & "<br>" & _
                    "<b>Last Name:</b> " & sLastName & "<br>" & _
                    "<b>First Name:</b> " & sFirstName
    End If
   End If
   oConn.Close
  End Sub 
  
  getUser(getLogon)  
%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top