Using the Debugger


The .NET framework includes a visual debugger that enables you to step line-by-line through the statements of an executing ASP.NET page. You can use the debugger to create breakpoints and watches, to view the values of variables at any point during page execution. In the following sections, you learn how to set up the debugger and create breakpoints and watches .

NOTE

The debugger included with the .NET framework is the same as the debugger included with Visual Studio .Net, except that the .NET framework debugger is missing some features. For example, the .NET framework debugger does not support remote debugging.


Attaching the Debugger

Before you can use the debugger, you must place your ASP.NET application in debug mode. The debugger requires the extra symbol information generated in debug mode to associate executing statements with the appropriate source code. To place your application in debug mode, include the Web.Config file in Listing 18.27 in the root directory of your application.

Listing 18.27 DebugMode/Web.Config
 <configuration>   <system.web>     <compilation debug="true" />   </system.web> </configuration> 

The C# version of this code can be found on the CD-ROM.

To start debugging an ASP.NET page, follow these steps:

  1. Request the page that you want to debug with your Web browser. Requesting the page ensures that the correct ASP.NET application is executing.

  2. Launch the debugger named DbgClr.exe . You can find it in the GuiDebug subdirectory in the Framework SDK install directory.

  3. Click the Open File button to open the ASP.NET page that you want to debug.

  4. Select Debug, Processes to open the Processes dialog box.

  5. Select Show system processes, select the aspnet_wp.exe process, and click Attach

  6. Close the Processes dialog box.

CAUTION

Never use the debugger on a production Web site. When you attach the debugger to an ASP.NET application, it freezes requests to the application.


Creating Breakpoints

Before you can debug an ASP.NET page, you must first specify one or more breakpoints in page execution. When an executing page reaches a breakpoint, the debugger enters break mode. You can view the values of variables only when the debugger is in break mode.

To set a break point within the debugger, click the margin on the left of the statement where you want the breakpoint to occur. Clicking the margin should cause a solid red dot to appear to signify the breakpoint (see Figure 18.12). You can add as many breakpoints to a page as you want.

Figure 18.12. Setting a breakpoint.

graphics/18fig12.jpg

If you hover your mouse pointer over a breakpoint, a ToolTip displays the line number of the ASP.NET application that is associated with the breakpoint.

After you create at least one breakpoint, request the page that you are debugging within a Web browser. The debugger should gain window focus when the breakpoint is reached. The debugger automatically enters break mode.

Creating Watches

When the debugger is in break mode after reaching a breakpoint, you can view the current values of the variables in a page in several ways.

The easiest way to view the value of any variable in the debugger is to hover the mouse pointer over the name of the variable. A ToolTip displays the current value of the variable.

Alternatively, you can open the Quick Watch dialog box by selecting Debug, Quick Watch. You also can automatically add a variable to the Quick Watch dialog box by right-clicking the name of the variable and selecting Quick Watch.

Within the Quick Watch dialog box, you can view the value of any variable by entering its name in the Expression text box and clicking Recalculate. You can also assign a new value to any variable within the Quick Watch dialog box by clicking its current value and entering a new value.

Finally, you can add a watch to the debugger. Within the Quick Watch dialog box, click the Add Watch button. Outside Quick Watch, right-click the name of a variable and select Add Watch. Either method adds the variable to the Watch window. You can edit the value of any variable in the Watch window by clicking its current value and entering a new value.

After you add a watch for a variable to the Watch window, the Watch window continues to display the current value of the variable as you step through each line in the ASP.NET page.

Stepping Through an ASP.NET Page

After the debugger hits a breakpoint, you can continue execution in several ways. If you want the page to continue executing until the next breakpoint is reached, you can click the Continue button (the VCR play button).

You also can continue page execution by selecting any of the following options from the Debug menu:

  • Step Into Executes the next unit of code. Step Into executes each unit of code in a function or subroutine individually.

  • Step Over Executes the next unit of code. Step Over executes an entire function or subroutine without executing each unit of code individually.

  • Step Out Executes the remainder of a function or subroutine and enters break mode when executed within the function or subroutine.

You can use Step Into, Step Over, and Step Out with different units of execution. You can step by statement, line, or instruction. To select the unit of execution, choose Debug, Step By.



ASP.NET Unleashed
ASP.NET 4 Unleashed
ISBN: 0672331128
EAN: 2147483647
Year: 2003
Pages: 263

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net