views:

61

answers:

1

I'm trying to get this code working within an asp page. when the user clicks an OnClick button, it will take them to this page which will create a file to store that user's username and the time they executed the code. So far, when this code runs, it will create the "userinfo.flag" file but it does not capture the user's data. Basically, i'm not grabing the users data correctly.

<%
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
Set NewTextFile = FSO.OpenTextFile(server.mappath("UserInfo.flag"),2,true)
Set WshNetwork = WScript.CreateObject("WScript.Network")
WScript.Echo "User Name = " & WshNetwork.UserName
NewTextFile.WriteLine("user:")
NewTextFile.WriteLine(WshNetwork.userName)
NewTextFile.WriteLine(Now)
NewTextFile.Close
Set NewTextFile = Nothing
Set FSO = Nothing

%>

<HTML>
<HEAD>
<TITLE>TEST PAGE</TITLE>
</HEAD>
</HTML>
A: 

When working in an .asp environment you don't have all the same global variables available as in a .vbs environment. Here are some things:

  • Don't use the WshNetwork object for finding information about the user. That information (if the user is authenticated) is available in Request.ServerVariables["AUTH_USER"]
  • Use Response.Write instead of WScript.Echo

That should get you the user information right.

Manne
Thanks. this did the trick: user = Request.ServerVariables("AUTH_USER") NewTextFile.WriteLine("user:")NewTextFile.WriteLine(user)but i have to find the right syntax for a time/date stamp:NewTextFile.WriteLine(Now)
MG