Share via

Enabling Tracing for a Page

You can control whether tracing is enabled or disabled for a page with the Trace attribute of the @ Page directive. Regardless of whether you write messages to the trace log, when you enable tracing and the page is requested, ASP.NET appends a series of tables containing performance information about the page request.

Tracing is disabled by default. If you do not include a Trace attribute in your page, trace information is not gathered, and trace statements you write do not appear on the page.

To enable tracing for a page

  1. Include an @ Page directive at the beginning of your .aspx file. Include the Trace attribute, and set its value to true.

    <%@ Page Trace="true" %>

    Security Note   When tracing is enabled for a page, trace information is displayed on any browser that makes a request for the page from the server. Tracing displays sensitive information, such as the values of server variables, and can therefore represent a security threat. Be sure to disable page tracing for the page before porting your application to a production server. You can do this by setting the Trace attribute to false, or by removing it.

  2. Optionally, include the TraceMode attribute to specify the order in which you want your trace messages to appear. Set the attribute to SortByTime to sort the messages in the order in which they are processed. Set the attribute to SortByCategory to sort them by the categories you specified in the Trace.Warn and Trace.Write method calls in your page or server control code.

    The following example, when included at the top of a page, sorts the trace messages of the page and of the server control contained in that page by category.

    <%@ Page Language="VB" Trace="True" TraceMode="SortByCategory" %>

The following screen shot illustrates a page with trace information appended to the end of the page output.

Page tracing


See Also

TraceContext Class | Page Class | ASP.NET Trace | @ Page | Writing Trace Messages