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

Obtaining User Information in ASP

Status
Not open for further replies.

byrne1

Programmer
Aug 7, 2001
415
US
Is there a way to get the user name from a client PC in ASP? For example, in VB I use the following code to get the name of the user that is currently logged on to the PC:

Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function GetUser() As String
Dim lpUserID As String
Dim nBuffer As Long
Dim Ret As Long
lpUserID = String(25, 0)
nBuffer = 25
Ret = GetUserName(lpUserID, nBuffer)

If Ret Then
GetUser$ = lpUserID$
End If
End Function


Is there any way I can duplicate this in ASP?
 
You can use :

<%=Request.ServerVariables(&quot;LOGON_USER&quot;)%>

but within IIS you need 'allow anonomous user' to be unchecked.
 
Within the ASP Request.ServerVariables(&quot;REMOTE_USER&quot;) seems to get the user who is logged in iff your web site disables Anonymous Login and enables Integrated Windows Authentication within Directory Security tab.

The VB equivalent can be accomplished by referencing COM+ Services Type Library and a function like:
Code:
Public Function GetUserName() As String
Const strSecError = &quot;SecurityError&quot;    
On Error GoTo Exit_Routine
    
    Dim secCallCtx      As SecurityCallContext
    Dim secIdent        As SecurityIdentity
    Dim x               As Boolean
    Dim oContext        As ObjectContext
    Dim sUserName       As String
    
    Set oContext = GetObjectContext()
    
    Set secCallCtx = GetSecurityCallContext()
    Set secIdent = GetSecurityCallContext(&quot;DirectCaller&quot;)
    
    x = secCallCtx.IsSecurityEnabled()
    
    If x = True Then
        sUserName = secIdent.Item(&quot;accountName&quot;)
    Else
        sUserName = &quot;Security Disabled&quot;
    End If

    GetUserName = sUserName
  
    oContext.SetComplete
    
    GoTo Closing:

Exit_Routine:
    oContext.SetAbort
    GetUserName = strSecError
    Err.Raise Err.Number, Err.Source, Err.Description, Err.HelpFile, Err.HelpContext

Closing:
    setCallCtx = Nothing

End Function

My question is which method is more accurate or consistent under Intranet circumstances???
 
I tried the Request.ServerVariables(&quot;REMOTE_USER&quot;) as referenced above but it doesn't return anything. I just end up w/ an empty string. Am I not invoking this command correctly?
 
Have you set the security through IIS on the web site? It will need that with Anonymous Logon disabled for the Request.ServerVariables(&quot;REMOTE_USER&quot;), Request.ServerVariables(&quot;AUTH_USER&quot;), and Request.ServerVariables(&quot;LOGON_USER&quot;) to work. -Ovatvvon :-Q
 
I've turned off Anonymous Login and have enabled Windows Challenge/Response security for everything in my directory, but I still get nothing for LOGON_USER, REMOTE_USER, or AUTH_USER.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top