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

Request.serverVariables("LOGON_USER")=""

Status
Not open for further replies.

SonJ

Programmer
Oct 24, 2002
166
0
0
GB
Hi,

I am trying to solve an intermittent error that I keep getting on one of the web applications that I have developed.

There is a check performed which gets the logon name of the current user to determine if the person is an administrator. The main part of this function is that it uses the request.servervariables("LOGON_USER") call to find the name of the person that is logged on. In some cases it works fine and in other cases it does not, and a custom error message displays. When I refresh the page the error sometimes remains and at other time disappear.

Does anyone know what is causing this. I am really perplexed as to why this is the case.

Code is as follows:
Code:
function GetNTUsername()
  strUserName=Request.ServerVariables("logon_user")
  for intLoop=1 to len(strUserName) ' remove the domain name from logon_user
  if mid(strUserName, intLoop,1)="\" then
    intSplitPos=intLoop
  end if
  next
  GetNTUsername=UCase(Right(strUserName,Len(strUserName)-intSplitPos))
end function

'find out if our current user is an administrator

strThisUser=GetNTUserName

'Response.Write &quot;logon_user: &quot; & Request.ServerVariables(&quot;LOGON_USER&quot;) & &quot;<BR><BR>&quot;
'Response.Write &quot;auth_user: &quot; & Request.ServerVariables(&quot;AUTH_USER&quot;) & &quot;<BR><BR>&quot;
'Response.Write &quot;strThisUser: &quot; & strThisUser & &quot;<BR><BR>&quot;

strSQLTemp=&quot;Select * from TableName WHERE FieldName='&quot; & strThisUser & &quot;'&quot;

call OpenDatabase
call CreateCommand

objCmdTemp.CommandText=strSQLTemp
set objRecIsAdmin=server.CreateObject(&quot;ADODB.Recordset&quot;)
objRecIsAdmin.Open objCmdTemp, , adOpenStatic, adLockOptimistic

if objRecIsAdmin.EOF then
  blnIsAdmin=false
else
  blnIsAdmin=true
end if

objRecIsAdmin.Close
set objRecIsAdmin=nothing
   
call CloseDatabase

Any pointers would help!

SonD
 
In IIS I know you need to disable &quot;Anonymous&quot; access for the web page and enable &quot;Authenticated Access&quot;. But if it works sometimes, then you probably allready did this.

What is the error message you recieve?

Try this instead of your function.
'----[BEGIN]------------------------------
Set Login = Request.ServerVariables(&quot;LOGON_USER&quot;)
L=Len(Login)
LL=InStr(Login, &quot;\&quot;)
StringLen=L-LL
User = (Right(Login, StringLen))
'----[END]--------------------------------
 
The variable just doesn't seem to be getting set on some occassions and does on others. I have an custom error message that appears saying &quot;You do not have admin access&quot; if the relevant username is not found in the table in the database.

As for altering the function, I will try. However, I have rewritten this function several times all to no avail!

SonD [dazed]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top