How To Debug an ASP.NET Application with the Microsoft CLR Debugger

 This article was previously published under Q301058

On This Page

      • Requirements
        • Configuring the Application
          • Enable Debugging in Web.config
            • Generate Symbolic Information for Precompiled Components
            • Debugging the Application
              • Notes
              • REFERENCES


                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.

                Back to the top

                MORE INFORMATION

                Back to the top


                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:
                	<compile debug=true/>
                Alternatively, you can set the Debug attribute of the Page directive to true in your .aspx pages, as follows:
                <%@ Page Debug="true" %>

                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
                1. Open the ASP.NET Web Application project in Visual Studio .NET.
                2. Right-click the project in the Solution Explorer and click Properties.
                3. In the Properties dialog box, click the Configuration Properties folder.
                4. In the left pane, select Build.
                5. Set Generate Debugging Information to true.
                6. Close the Properties dialog box.
                7. Right-click the project and click Build to compile the project and generate symbols (.pdb files).
                Using Command Line Compilers

                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

                1. 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\GuiDebug
                  When 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
                2. Use a Web browser to browse to the application that you want to debug to ensure that the Aspnet_wp.exe process is started.
                3. Open the source file that you want to debug: on the File menu in the CLR Debugger, click Open.
                4. On the Tools menu, click Debug Processes.
                5. In the Processes dialog box, select Show system processes.
                6. Double-click Aspnet_wp.exe and verify that it appears in the Debugged Processes list. Close the Processes dialog box.
                7. 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.
                8. 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.

                Back to the top


                For more information on the Microsoft DbgCLR debugger, visit the following Microsoft Web site:
                Debugging with the Microsoft .NET Framework SDK
                For more general information about ASP.NET, visit the following MSDN newsgroup:For additional information about how to perform this task by using Microsoft Active Server Pages, click the article number below to view the article in the Microsoft Knowledge Base:
                299986  How To Use an ASP Debug Object to Debug ASP Pages
                Back to the top

                APPLIES TO
                • Microsoft ASP.NET 1.0
                • Microsoft .NET Framework Software Development Kit 1.0
                • Microsoft .NET Framework Service Pack 2
                • Microsoft ASP.NET 1.1
                • Microsoft .NET Framework Software Development Kit 1.0 Service Pack 2
                • Microsoft Common Language Runtime (included with the .NET Framework 1.1)
                Back to the top
                kbdebug kbhowtomaster KB301058


                Popular posts from this blog

                How To Implement Forms-Based Authentication in Your ASP.NET Application by Using C# .NET

                Microsoft Teams: Group Chat Software

                Microsoft Edge browser