Debug Your Web Matrix Code
Use Microsoft's CLR Debugger utility to step your way through the ASP.NET code you built with Web Matrix.
by Jonathan Goodyear, MCSD, MCP, CLS
Posted April 4, 2003
In case you've been using a free tool called Web Matrix for ASP.NET development, you should know that Web Matrix might not be your best choice—even for small projects. It lacks some key features, such as an integrated debugger. This article explains how to debug Web Matrix ASP.NET pages using Microsoft's DbgCLR.exe utility, which comes with both the .NET Framework and Visual Studio .NET (see Resources).
The method you choose to debug your Web Matrix ASP.NET pages depends on what you use as a host: the lightweight Web server that comes with Web Matrix or Microsoft Internet Information Services (IIS).
Debug Using Web Matrix Server
Create a directory named WebMatrixDebugging in your C:\data\webs\ folder. The location of your Web Matrix ASP.NET files doesn't matter. Next, launch Web Matrix and create a new ASP.NET page (my language choice is C#) named DebugTest1.aspx in the directory that you just created.
You should now be looking at the blank design surface of the DebugTest1.aspx page. On the Properties window, click on the upper drop-down menu and select System.Web.UI.Page. Then click on the icon just below it that looks like a lightning bolt. This lists the events for your ASP.NET page. Double-click on the Load event, which changes your main viewing area to code view, and insert this Page_Load event procedure:
void Page_Load(Object sender,
EventArgs e)
{
int x = 1;
int y = 0;
int z = x / y;
Controls.Add(new LiteralControl
(z.ToString()));
}
To run the code, click on the Start icon on the toolbar—it looks like the typical play button on a CD player or VCR. In the dialog box that appears, select whether you want to use ASP.NET Web Matrix Server or create an IIS virtual root (see Figure 1). For now, select the first option. The port doesn't matter, as long as no other application on your system uses it. The default port 9000, as shown in the figure, usually works well. As your page starts up, notice that a new icon appears in your system tray for Microsoft ASP.NET Web Matrix Server (see Figure 2).
The page has, of course, failed because of an "attempted to divide by zero" error. Just look at the code. But for a moment pretend you can't determine the source of the problem. This is where Microsoft's DbgCLR.exe utility comes in handy. First, though, you need to make a slight modification to your ASP.NET page. Close the browser window and click on the All tab under the code editor in the Web Matrix IDE. At the top of the page, add the debug="true" attribute to the @Page directive.
Now that your ASP.NET page is set up for debugging, locate the DbgCLR.exe utility. If you only have the .NET Framework installed, you can find it in C:\Program Files\Microsoft.NET\FrameworkSDK\GuiDebug\. If you have Visual Studio .NET installed, you'll see it in C:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\GuiDebug\.
Back to top
|