Tracing
The tracing feature in ASP.NET is useful in tracking the execution of an application. This is helpful to display the trace in a way that doesn’t affect the programs output.
To enable tracing on a page-by-page level, set the Page directive in any ASP.NET page to True:
<%@ Page Language=”C#” Trace=”true” TraceMode = “SortByCategory” Inherits = “System.Web.UI.Page” CodeFile=”Default.aspx.cs” %>
To enable tracing for an entire application add tracing settings to the web.config:
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<compilation debug=”false” />
<authentication mode=”Windows” />
<trace enabled =”true” pageOutput =”True” requestLimit =”20″ traceMode =”SortByTime ” />
</system.web>
</configuration>
The page-level setting will take precedence over the web.config setting.
How to view Trace Data.
In the Page_Load event call System.Diagnostics.Trace.Write(). Make sure the pageOutput=True in the webConfig.
What’s being displayed
1. Request Details
ASP.NET Session ID, Character encoding of the request.
2. Trace information
All Trace.write methods called in the HTTP request. This is helpful to find methods that are taking a long time to execute.
3. Control Tree
HTML of ASP.NET Control Tree.
4. Session State
List all keys and values for users session .
5. Application State
List all keys and values for application.
6. Request Cookies Collection
List all cookies passed in during page request.
7. Response Cookies Collection
List all cookies passed back during page response.
8. Headers Collection
Shows all headers passed in during request from browser.
9. Response Headers Collection
Shows all headers passed back during response.
10. Form Collection
Displays dump of Form Collection and all keys and values.
11. Querystring Collection
Displays dump of Querystring collection and all keys and values.
12. Server Variables
Displays dump of Server Variables with keys and values.
The Trace.axd
Page output only displays information of the current page. If you want to create a collection use Trace.axd.
http://localhost/application-name/trace.axd
Trace.axd will display all tracing data up to the present limit.
Trace Forwarding
ASP.NET allows to forward trace message to System.Diagnostics.Trace:write to DiagnosticsTrace
<trace enabled =”true” requestLimit =”20″ writeToDiagnosticsTrace =”true ” pageOutput =”true”/>