The Microsoft .NET Framework Software Development Kit (SDK) contains a lightweight debugger for debugging .NET applications on computers that do not have Visual Studio .NET installed.
This article describes how to configure your ASP.NET application for debugging, how to attach to the ASP.NET worker process (Aspnet_wp.exe) with the Microsoft CLR Debugger, and how to debug the application.
The following list outlines the recommended hardware, software, network infrastructure, skills and knowledge, and service packs that are required:
- Microsoft Windows 2000 or Microsoft Windows XP
- Microsoft .NET Framework
- Microsoft .NET Framework Software Development Kit (SDK)
- Microsoft Internet Information Server (IIS) 5.0 or later
Configuring the Application
Enable Debugging in Web.config
Because many parts of an ASP.NET application (such as .aspx, .asmx and .ascx pages) are dynamically compiled at run-time, you need to configure the ASP.NET run-time process to compile the application with symbolic information before the application can be debugged. To do this, set the debug
attribute in the configuration section of the Web.config file that is located in the root of the application folder to true
, as follows:
<configuration> <compile debug=true/></configuration>
Alternatively, you can set the Debug
attribute of the Page
directive to true
in your .aspx pages, as follows:
Generate Symbolic Information for Precompiled Components
To debug precompiled components such as business objects and code-behind modules, you need to generate debug symbols. To do this, compile the components with the debug flags by using either Visual Studio .NET or a command line compiler such as Csc.exe (for Microsoft Visual C# .NET) or Vbc.exe (for Microsoft Visual Visual Basic .NET). Using Visual Studio .NET
Using Command Line Compilers
- Open the ASP.NET Web Application project in Visual Studio .NET.
- Right-click the project in the Solution Explorer and click Properties.
- In the Properties dialog box, click the Configuration Properties folder.
- In the left pane, select Build.
- Set Generate Debugging Information to true.
- Close the Properties dialog box.
- Right-click the project and click Build to compile the project and generate symbols (.pdb files).
Use Csc.exe for Visual C# .NET or Vbc.exe for Visual Basic .NET to compile your application with the debug:full
switch to generate complete symbolic information, as follows:
csc /debug:full /out:assemblyname.dll file1.cs file2.cs ... fileN.cs
vbc /debug:full /out:assemblyname.dll file1.vb file2.vb ... fileN.vb
Debugging the Application
- Start Dbgclr.exe from the folder in which you installed the Microsoft .NET Framework SDK. By default, and depending on whether you installed the .NET Framework SDK separately or as part of a Visual Studio .NET installation, this folder is in the following location:
C:\Program Files\Microsoft.Net\FrameworkSDK\GuiDebug - or -
C:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\GuiDebugWhen you install Microsoft.Net Framework 1.1, Dbgclr.exe is located in the following folder:
C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\GuiDebug
- Use a Web browser to browse to the application that you want to debug to ensure that the Aspnet_wp.exe process is started.
- Open the source file that you want to debug: on the File menu in the CLR Debugger, click Open.
- On the Tools menu, click Debug Processes.
- In the Processes dialog box, select Show system processes.
- Double-click Aspnet_wp.exe and verify that it appears in the Debugged Processes list. Close the Processes dialog box.
- Set a breakpoint in the source file:
- Either select the line on which you want to set the breakpoint, and then press F9.
- or -
- Click in the margin by the line on which you want to set the breakpoint.
- Browse to the page that you are debugging, or, if the page is already open in the browser, click Refresh. The debugger regains focus and stops on the breakpoint. From this point you can step through the code, set watches, and see local variables.
To see the ASP.NET intrinsic objects, add the this
pointer to the watch window for Visual C# .NET or Me
for Visual Basic .NET.
When the debug
attribute in the Web.config file is set to true
, it generates symbolic information every time the compiler compiles your .aspx pages as well as disables code optimization. If the application is not being debugged, you should change this attribute to false
While the debugger is attached and in break mode, no requests to pages in the application execute. Therefore, you should not debug an application on a production Web server while it is in use.
Only one debugger can be attached to the Aspnet_wp.exe process at a time.
The CLR Debugger only debugs managed code, and it only debugs applications on the computer on which the CLR Debugger is running. If you need to debug remotely or if you need to debug code other than managed code, you should use the Visual Studio .NET debugger.