Debugging ASP.NET


There is nothing special about the process of debugging Web applications. You do things such as set breakpoints, step through the code, examine variables, and so on. The tricky part is configuring Visual Studio .NET so that you can actually run the debugger. This requires two steps to be completed.

The first step is to make sure you have in the Web application's root virtual directory a Web.config file with compilation tag that has a debug attribute set to true:

 <compilation debug="true" /> 

Caution

The preceding code is case sensitive. You must enter the attribute exactly as shown previously or debug mode will not be set.

With debug mode set, the ASP.NET runtime will generate debugging symbols for a dynamically generated Web page class. It also enables the debugger to attach to the Web application.

Note

Enabling debug mode greatly affects the performance of your ASP.NET application. You should disable debug mode before you deploy your Web application.

The second step is to update your configuration debug properties to support debugging. This requires you to perform the following steps:

  1. Open up the Properties of the Web application.

  2. Select the Debugging folder (see Figure 14-8).

    click to expand
    Figure 14-8: The HelloWorld Configuration Properties Debugging folder

  3. Set the Command to aspnet_wp.exe. It might be required that you set the entire path to aspnet_wp.exe if the aspnet_wp.exe executable is not on the executables path.

  4. Set Attach to yes.

Notice that the HTTP URL is already set correctly because you entered it when you executed the Web page earlier.

After you close the configuration dialog box, you press the F5 key to start debugging your Web Form or select Start from the Debug main menu. Figure 14-9 shows HelloWorld stopped at a breakpoint.

click to expand
Figure 14-9: Debugging HelloWorld

Tip

If you get a dialog box that displays the message "Unable to start debugging on the Web server" instead of your Web application, when you start your debugging session, try specifying your machine name instead of "localhost" in the HTTP URL edit box. For example, on my system I would enter http://Amidala/HelloWorld/HelloWorld.aspx.




Managed C++ and. NET Development
Managed C++ and .NET Development: Visual Studio .NET 2003 Edition
ISBN: 1590590333
EAN: 2147483647
Year: 2005
Pages: 169

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