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

Question on request.servervariables

Status
Not open for further replies.

fmrock

Programmer
Sep 5, 2006
510
US
I am very new to asp.net but have done asp and vb for a while. I am having to edit an existing .net app and want to add some logging. I added this into the .vb page and creates the file and does the logging.

What would be the best way to get the server variables Referrer and Querystring. I am really needed to log the query string.

I am looking around google and have not found anything yet.

Also, would this be the most efficient way to create the txt file and write to it?

Code:
            'Open a file for writing
            Dim Test_log_FILENAME As String = Server.MapPath("login_Log_" & DateTime.Now.ToString("yyyyMMdd") & ".txt")

            'Get a StreamReader class that can be used to read the file
            Dim objStreamWriter As StreamWriter
            objStreamWriter = File.AppendText(Apollo_log_FILENAME)

            Dim varQueryString As String
            Dim varIPAddress As String
            Dim varReferrer As String

            varQueryString = ""
            varIPAddress = Request.UserHostAddress
            varReferrer = ""

            objStreamWriter.WriteLine(DateTime.Now.ToString() & ":  " & "-------------------")
            objStreamWriter.WriteLine(DateTime.Now.ToString() & ":  " & "Query String: " & varQueryString)
            objStreamWriter.WriteLine(DateTime.Now.ToString() & ":  " & "IP Address: " & varIPAddress)
            objStreamWriter.WriteLine(DateTime.Now.ToString() & ":  " & "Referrer: " & varReferrer)
            objStreamWriter.WriteLine(DateTime.Now.ToString() & ":  " & "-------------------")

            'Close the stream
            objStreamWriter.Close()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top