Recipe 13.3. Uncovering Application-Wide Problems


You want to find the sources of problems at any point in an application, but you don't want to have to change every page to do so, nor do you want to disrupt the output of your application pages.


Enable application-level tracing in the application web.config file and view the AXD application trace log for your application.

  1. Locate the web.config file in the root directory of your application (or create one if it does not exist).

  2. Enable application-level tracing by adding a <trace> element to the <system.web> section of web.config and setting its enabled attribute to "true":

     <configuration> <system.web> <trace enabled="true" /> </system.web> </configuration> 

  3. View the application trace log by browsing to the trace.axd page from the application root, like this:


Figure 13-2 shows some sample trace log output.

Figure 13-2. Application-level tracing output (trace.axd)


By adding a <trace> element to web.config and setting its enabled attribute to "TRue", you can activate application-level tracing.

 <trace enabled="true" /> 

What happens is that ASP.NET collects trace information for each HTTP request to the application and directs it to the application trace log. You can view the application trace log in the trace viewer. To view the trace viewer, request trace.axd from the root of your application directory:


The trace.axd is not a page but rather a special URL intercepted by ASP.NET. The trace.axd is an HTTP handler, the equivalent of an ISAPI extension. Chapter 20 provides recipes on how to create your own HTTP handlers.

The trace.axd shows you a sequential listing of the HTTP requests processed by your application, as shown in Figure 13-2.

Here are some of the more commonly used <trace> element attributes:


The default number of HTTP requests stored in the application trace log is 10. You can increase the number of HTTP requests using the requestLimit attribute:

 <trace enabled="true" requestLimit="40" /> 

Once the limit is reached, if the mostRecent attribute is set false, then no other HTTP requests will be logged until the application is restarted, or you hit the "clear current trace" link on the trace.axd page (see the upper-right corner of Figure 13-2), or the query string clear=1 is passed to trace.axd, like so:



The default value is false, which indicates that once the requestLimit is reached, no additional trace information is stored. You can set the value to TRue if you want to see the most recent requests.


If, in addition to viewing the trace.axd file, you want to see trace information displayed at the bottom of the page that it is associated with, add pageOutput="true" to the <trace> element:

 <trace enabled="true" pageOutput="true" /> 

The trace information you will see is identical to what would appear had you placed TRace="true" in the @ Page directive for the page (see Recipe 13.1 for details).


To show trace information to the local user (i.e., the browser making the request is on the machine serving the request) but not to remote users, ensure the <trace> element includes localOnly="true":

 <trace enabled="true" pageOutput="true" localOnly="true" /> 

If you are viewing the trace log in the trace viewer and you want to see specific information about a request, like the kind you see in Figure 13-1, click the "View Details" link to the right.

When deploying your application to a production environment, you can explicitly disable trace.axd by placing <httpHandler> elements like these in web.config:

 <configuration> <system.web> <httpHandlers> <remove verb="*" path="trace.axd" /> </httpHandlers> </system.web> </configuration> 

See Also

Recipe 13.1 and Chapter 20

ASP. NET Cookbook
ASP.Net 2.0 Cookbook (Cookbooks (OReilly))
ISBN: 0596100647
EAN: 2147483647
Year: 2003
Pages: 202

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: