Developing Web Applications |
ASP debug tracing is limited to the following three methods:
Implement debug tracing wisely. When you have to insert debug messages into your script, you should emphasize events that might enable you to reconstruct the flow through the code leading up to an error. Capture function calls and values of parameters. Log important values only; if you write too many messages, you can slow down the application considerably.
Try to make it easy to disable and enable debug tracing. For small projects, it’s okay to comment out the debug trace statements that you want to disable. For larger projects, however, you should encapsulate the debug trace code in a script or component function that can be enabled and disabled independently of the code.
Debugging Session and Application events can be tricky, because you can’t use the Response.Write method to display messages to the client browser. One useful technique is to use the Scripting.FileSystemObject to generate a simple log file with text messages indicating the success or failure of these events. The following script writes notifications for Application start and end events, as well as for every Session start and end event.
<!--METADATA TYPE="TypeLib"
NAME="Scripting" FILE="C:\Winnt\System32\scrrun.dll"
UUID="420B2830-E718-11CF-893D-00A0C9054228" VERSION="1.0"
-->
<OBJECT ID="AppFileSystemObject" SCOPE=APPLICATION RUNAT=SERVER
PROGID="Scripting.FileSystemObject">
</OBJECT>
<SCRIPT LANGUAGE=VBScript RUNAT=SERVER>
Sub OutputDebugFile(ByRef strText)
Dim ts
Application.Lock
Set ts = AppFileSystemObject.OpenTextFile(Application("DebugFile"),_
ForAppending, True, TristateUseDefault)
ts.WriteLine Now & ": " & strText
ts.Close
Application.Unlock
End Sub
Sub Application_OnStart
'DebugFile must be defined before calling OutputDebugFile.
Application("DebugFile") = "c:\webs\appevnts.log"
OutputDebugFile("Application Started")
End Sub
Sub Application_OnEnd
OutputDebugFile("Application Ended")
End Sub
Sub Session_OnStart
OutputDebugFile("Session Started: " & Session.SessionID)
Response.Redirect "./end.asp" 'End Session (this creates a loop!).
End Sub
Sub Session_OnEnd
OutputDebugFile("Session Ended: " & Session.SessionID)
End Sub
</SCRIPT>