Tracing is an easy way to determine what is going on in your program. Back in the days of classic ASP, the only way to trace what was happening in your code was to insert Response.Write statements in strategic places. This allowed you to see that you had reached a known point in the code and, perhaps, to display the value of some variables. The big problem with this hand-tracing technique, aside from the amount of work involved, was that you had to laboriously remove or comment out all those statements before the program went into production.

ASP.NET provides better ways of gathering the trace information. You can add tracing at the application level or at the page level. With application-level tracing every page is traced, and with page-level tracing you choose the pages to which to add tracing.

Page-Level Tracing

To add page-level tracing, modify the Page directive at the top of your .aspx page, by adding a Trace attribute and setting its value to true. For example, to enable tracing on Default.aspx, the Page directive should read as follows:

<%@ Page Language="C#" AutoEventWireup="true"
   CodeFile="Default.aspx.cs" Inherits="_Default"
   Trace="true" %>

Now when you save and view Default.aspx, there will be tables at the bottom that contain a wealth of information about your web application, as shown in Figure 19-2.

Some trace information for Default.aspx

Figure 19-2. Some trace information for Default.aspx

The top section, ...

Get Programming ASP.NET 3.5, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.