Debugging the ASP.NET Sample Application

In general, debugging an ASP.NET application requires the following three steps.

  1. Start the application.
  2. Start the debugger, and perform the following three substeps.
    1. Attach to the ASP.NET process, aspnet_wp.exe.
    2. Open the source code file(s).
    3. Set breaking conditions.
  3. Refresh the application (which jumps to the debugger).

Before running the debugging sample, you must first configure a virtual root for the application. This can be automatically accomplished by running the CreateVroot.vbs script file or by running BuildAll.bat, which calls the same .vbs script file. Both files are located in the tutorial's main directory.

Step 1 — Assuming you used one of the just-described methods to create a virtual root named debug, open a browser and navigate to https://localhost/netsdk/debug/default.aspx. You should see a screen that looks like this:

Your application starts running when you first access a page in the application's virtual root.

Step 2 — Now that it is running, you can attach the debugger. To use the Windows-based common language runtime debugger, run the DbgClr.exe program in the \GuiDebug subdirectory under the .NET Framework SDK installation directory.

Step 2a — Select Debug Processes from the Tools menu to display the Debug Processes dialog box. Since ASP.NET is a system process, the Show system processes option must be selected. The Available Processes grid should now include a process named aspnet_wp.exe, which you should select. Click the Attach button. The Debug Processes dialog box should now look like this:

Step 2b — Open both Default.aspx and Default.cs, which contains the Visual C# code behind the ASP.NET page.

Step 2c — Set a breakpoint in Default.aspx (which contains the img tag) by pressing F9, pressing CTRL+B, clicking in the right margin, or selecting the line and choosing New Breakpoint from the Debug menu. Then set a breakpoint in Default.cs — specifically in the first line of the Page_Load method.

Step 3 — Returning to the browser, refresh the page. You should then break into the Default.cs file in the debugger and see a display similar to the following:

You can examine variables in the Locals window. If the window is not visible, choose Windows from the Debug menu, and choose Locals. You can also rest the mouse pointer over code to see values. (Resting the mouse pointer over the Object sender procedure argument produces a tool window containing sender = {ASP.default_aspx}.)

At this point, you can continue into the Web-page code by pressing F5.

**Note   **You can expand the Me variable, and then the MyCodeBehind variable, to examine variables created by code in Default.cs.

See Also

Appendix A: For Additional Information | Appendix B: Runtime Debugger (CorDbg.exe)