Debugging a Global.asa File

See Also

Debugging a Global.asa file differs from debugging .asp files in

these ways:

Before you can debug script in the Global.asa page, you must enable debugging for ASP pages.

To enable script debugging in ASP pages

  1. In the Project Explorer, right-click the project and choose Properties to display the Property Pages dialog box.

  2. Choose the Launch tab.

  3. Under Server script, choose Automatically enable ASP server-side debugging on launch.

To debug the Global.asa file, you can call the debugger from a script or respond to an error.

To call the debugger from the Global.asa file

When the application starts or when a user starts a new session, the corresponding procedure in a Global.asa file will run. The debugger will start when the Stop or debugger statement is executed. You can then step through the procedure normally, use the Immediate window to evaluate expressions and set values, and so on.

If there is an error in a Global.asa file (either a syntax error or runtime error), the server stops the procedure containing the error. If the debugger is enabled for that ASP application, the server prompts you to start the debugger and displays an error message. If the debugger is not enabled for the ASP application, an error message is sent to the client browser. In either case, the procedure containing the error stops.

To debug Global.asa script in response to an error

  1. In response to the error, choose Yes.

    If Visual InterDev is not already running, it is launched. The debugger attaches itself to the script with the error and displays the page in the editor.

  2. If the page is part of a project in Visual InterDev, fix any errors, save the file, and then choose Restart from the Debug menu. If you do not have a working copy of the file in your project, right-click the Global.asa file in the Project Explorer and choose Get Latest Version before making modifications.

You cannot stop and restart the script by refreshing a Global.asa file. To rerun Application_OnStart or Session_OnStart procedures, you must refresh the file or trigger the events again or otherwise restart the application.

To rerun all procedures in the Global.asa

To rerun Application_OnStart procedures

You can rerun Session_OnStart procedures by restarting a session.

To rerun Session_OnStart procedures

Debugging Script

See Also    Tasks

Debugging script allows you to find errors in your script, such as syntax errors, run-time errors, and logic errors, before you publish that script to the World Wide Web. You probably already know how to set breakpoints and how to step through lines of script. Now you can see how to accomplish these tasks using Microsoft Visual InterDev.

In Visual InterDev, debugging script consists of some or all of these steps, once you have added script to a page:

Adding Client Script to an HTM Page

Debugging client script is an easy way to become familiar with debugging in Visual InterDev. Client-side script is processed on the browser, while server-side script is processed on the Web server. For more information about client- and server-side script, see Debugging Client Script and Debugging Server Script.

The sample client script, located between the <SCRIPT> </SCRIPT> tags in the example below, validates the length of password entries made in a simple form. The remaining HTML tags define the form and do not participate in the script debugging process.

To use the script below, copy and paste the script and HTML into a new .htm file using Source view of the HTML editor. For more information, see Editing Script.

<SCRIPT LANGUAGE="JavaScript">
function validatePassword(){
var password; 
password = document.frm1.txtPassword.value;
alert("You entered " + password);
if (password.length < 4)
alert("You must enter 4 characters or more!");
else {
frm1.submit() ; }
}
</script>
<FORM NAME="frm1" METHOD="Post" ACTION="Process.asp" ONSUBMIT="validatePassword()">
   Please enter your password:<br>
   <INPUT TYPE="Password" NAME="txtPassword">
   <INPUT TYPE="Submit" NAME="btnSubmit">
</FORM>

Note   JavaScript is case sensitive, so the sample script above must appear exactly as it does here in your .htm file.

The script checks that the password length is four characters or greater. The script generates a message box listing the password the user entered. If the password is four characters or greater the user is then redirected to the page called by the Action element of the Form tag.

If you haven't created Process.asp, the browser will display the object not found error. If the password is less than four characters, a message box appears indicating the character length requirement.

Setting Breakpoints

To specify a place in script where you want to stop and examine the state of the process, you can use breakpoints. Breakpoints indicate the line of script you want to stop on in the program. You can then step through, step into, or step over lines of script individually to find errors. Breakpoints show up as red octagons to the left of a line of script in Source view.

Note   To debug client scripts in Microsoft Internet Explorer, you must be using Internet Explorer 4.0 and debugging must be enabled. For details, see the Internet Explorer documentation.

To set breakpoints

  1. Open the .htm file and select Source view.

  2. Place the cursor in the line of script you want to set a breakpoint in.

  3. From the Debug menu, choose Insert Breakpoint.

    A red octagon appears to the left of the line of script.

    Note   You can also set or remove a breakpoint by placing the cursor in a line of script and pressing F9.

To launch the debugger

  1. In the Project Explorer, right-click the .htm file and select Set As Start Page.

  2. Launch Internet Explorer 4.0 and load the .htm page into the browser.

  3. From the Debug menu in Visual InterDev, choose Processes.

    The Processes dialog box appears.

  4. In the Process area, select Microsoft Internet Explorer and then select Attach.

    Microsoft Internet Explorer and your machine name appear in the Debugged Processes area.

  5. In Internet Explorer, enter a password and choose Submit.

The script executes until Internet Explorer reaches the breakpoint. When Internet Explorer reaches the breakpoint, it stops and displays the source script in Source view.

A yellow arrow superimposed over the breakpoint icon indicates the line of script where the debugger stopped.

For more information, see Breakpoints Dialog Box or Debugging Client Script.

Stepping Through Lines of Script

To execute script one line at a time, you can use Step Into. After stepping through each line, you can view the affects of the statement by looking at the page in Internet Explorer.

To step into lines of script

  1. Open the .htm file in Source view and set a breakpoint at the following line of script:
    <FORM NAME="frm1" METHOD="Post" ACTION="Process.asp" ONSUBMIT="validatePassword()">
    

    Note   When you place a breakpoint in the line of HTML above, you are actually specifying that the script stop executing when you click the Submit button, ONSUBMIT="validatePassword()".

  2. Launch the debugger.

  3. Enter a two-character password and choose Submit.

    Internet Explorer reaches the breakpoint and switches to Source view. A yellow arrow appears superimposed over the breakpoint icon.

  4. From the Debug menu, choose Step Into and then choose Step Into a second time.

    The following line of script is highlighted:

    alert("You entered " + password);
    
  5. From the Debug menu, choose Step Into again.

    Internet Explorer executes the alert script and displays the message box.

  6. Choose OK.

    Internet Explorer reaches the next line of script and switches to Source view.

You can continue stepping into lines of script and view the results in Internet Explorer.

To execute procedures in script as a single unit, you can use Step Over. Step Over allows you to skip a procedure or function and step through the next procedure or function.

After stepping over a procedure, you can view the affects of the procedure by looking at the page in Internet Explorer.

To step over lines of script

  1. Open the .htm file in Source view and set a breakpoint at the following line of script:
    <FORM NAME="frm1" METHOD="Post" ACTION="Process.asp" ONSUBMIT="validatePassword()">
    

    Note   When you place a breakpoint in the line of HTML above, you are actually specifying that the script stop executing when you click the Submit button, ONSUBMIT="validatePassword()".

  2. Launch the debugger.

  3. Enter a three-character password, then choose Submit.

    Internet Explorer reaches the breakpoint and switches to Source view. A yellow arrow appears superimposed over the breakpoint icon.

  4. From the Debug menu, choose Step Over.

    Internet Explorer executed the following script as a procedure unit:

    password = document.frm1.txtPassword.value;
    alert("You entered " + password);
    if (password.length < 4)
    alert("You must enter 4 characters or more!");
    
  5. Choose OK in each alert message.

Internet Explorer reaches the line of script after the procedure unit and switches back to Source view. For more information, see Debugging Your Pages and Stepping Through Code to Trace Execution.

Changing the Value of a Variable

You can change the value of a variable from the Immediate window. When Internet Explorer reaches a breakpoint and switches to Source view, you can then change the value of a variable and view the results in the Locals window.

To change the value of a variable

  1. Open the .htm file in Source view and set a breakpoint at the following line of script:
    <FORM NAME="frm1" METHOD="Post" ACTION="Process.asp" ONSUBMIT="validatePassword()">
    
  2. Launch the debugger.

  3. Enter a three-character password and choose Submit.

    Internet Explorer reaches the breakpoint and switches to Source view. A yellow arrow appears superimposed over the breakpoint icon.

  4. From the Debug menu in Visual InterDev, choose Step Into.

  5. From the View menu, select Debug Windows and then select Immediate.

  6. In the Immediate window, type the following:
    password="test"
    
  7. Press Enter.

  8. From the View menu, select Debug Windows and then select Locals.

    The Locals window displays the new value of the variable you entered in the Immediate window.

For more information, see Executing Commands and Evaluating Expressions in the Immediate Window and Viewing Local Variables in the Locals Window.