5.2 Debugging


Because ASP.NET pages are compiled into assemblies, you can debug them in much the same way you might debug any other .NET component. First, you must be sure you compile your pages with debug symbols. To do this on a per-page basis, set the Debug attribute on the Page directive to true , as shown in Listing 5-1.

Listing 5-1 .aspx Page with Debug Compilation
 <%@ Page Language="VB" Debug="true" %> <!-- ... --> 

Alternatively, you can enable debug compilation for all the pages in your application by adding the compilation element to your web.config file with debug set to true , as shown in Listing 5-2.

Listing 5-2 web.config with Debug Compilation
 <configuration>   <system.web>     <compilation debug='true' />   </system.web> </configuration> 

Also keep in mind that any code-behind assemblies that you precompile must be built with debug symbols enabled in order to debug them with source display. Once debug symbols have been generated for your page assemblies, you can use the Visual Studio .NET debugger to step through any server-side or client-side code. If you are building a Web application with Visual Studio .NET, the simplest way to execute your program is with Debug/Start. If, on the other hand, you are trying to debug an application that is already running or that was not built with Visual Studio .NET, you can use the alternative technique of attaching to the ASP.NET worker process. To do this, select Debug/Processes from the menu within Visual Studio .NET. When presented with a dialog, select the aspnet_wp.exe process to attach. This will bring up a second dialog, displaying all the active AppDomains in the worker process. Select the AppDomain that has your virtual directory name in it, and attach. You can now open any source files from your application that you would like to debug, and place breakpoints as desired. Figure 5-5 shows the dialogs you are presented with when you attach to the process.

Figure 5-5. Attaching a Debugger to the ASP.NET Worker Process

graphics/05fig05.gif



Essential ASP.NET with Examples in Visual Basic .NET
Essential ASP.NET with Examples in Visual Basic .NET
ISBN: 0201760398
EAN: 2147483647
Year: 2003
Pages: 94
Authors: Fritz Onion

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