Tracing can be viewed for multiple page requests at the
application level by requesting a special page called trace.axd. We can enable
tracing in Web.config as shown in code Listing 3.
<compilation debug="false" />
<authentication mode="Windows" />
<trace enabled ="true" pageOutput ="true" />
protected void Page_Load(object sender, EventArgs e)
System.Diagnostics.Trace.Write("This is Page_Load method!");
Trace.Write() method can be used in the Page_Load event as
shown in the above code listing. We can also use the Trace.Warn method. When
Trace.Warn method is used the trace output will display the given message in
red. When we run the page, we can see (because we have set PageOutput=true) eleven
different sections in the browser which provide a great deal of information as
Request Details: This section includes the ASP.NET Session
ID, the character encoding of the request and response, the HTTP conversation's
returned status code, the time of request and the type of web request.
TraceInformation: This section shows the different stages of
processing that the page went through before being sent to the client. Each
section has additional information about how long it took to complete. The
timing information located here is valuable when profiling and searching for
methods in the application that take too long to execute.
Control Tree: Control tree presents an HTML representation
of the ASP.NET Control Tree. It shows each control's unique ID, run time type,
the number of bytes it took to be rendered, and the bytes it requires in View
State and Control State. This helps us determine whether the enabling control
state could affect page transmission times.
Session State: This section displays every item in a
particular user's session, their types and their values.
Application State: This section displays every item in the
current application's Application object and their type and values.
Request Cookies: This lists all the cookies passed in when the
page is requested.
Response Cookies: Lists all the cookies that were passed
back during the page's response.
Headers Collection: Shows all the headers that might be
passed in during the request from the browser, including Accept-Encoding,
indicating whether the browser supports the compressed HTTP responses and
Form Collection: This section displays all of the Form
Collection and all its keys and values.
QueryString Collection: This section displays the variables
and values submitted in the Querystring collection in the form of keys and
Server Variables: This section lists all the server
variables and their contents.
Trace.axd: Using page output of tracing we can get only the
data collected for the current page request. However, if we want to collect
detailed data for all the requests then we need to use Trace.axd. We can invoke
Trace.axd tool for the application using http://machinename/applicationname/trace.axd,
which is shown below.
In the above figure we can see that there are three request
that have been made to this application and "Remaining:7" in the
right side of the header suggests that there are seven more remaining requests
before tracing stops for this application. The request limit can be set in
Web.config which is already shown in code Listing 2.
Following are different options that we can set in
web.config file for application tracing:
Enabled: This turns tracing on or off for all pages. It can
be override on a page-by-page basis with the Page directive.
traceMode: Determines the sort order of trace messages.
Values are SortByTime and SortByCategory.
localOnly: It determines whether tracing information will be
visible only to the user of local computers or can be visible to the user of a
remote computer. By default it is true.
pageOutput: It determines whether tracing information will
be displayed on the page or not by setting values to true or false.
requestLimit: This is any integer number of page requests
that are stored and displayed via trace.axd when we are using application level
tracing. If we specify any value greater than 10000, ASP.NET treats it as
mostRecent: If true, ASP.NET keeps only the most recent
trace messages. If it reaches the maximum number, the oldest request is removed
whenever any new request comes. If it is false, ASP.NET stops collecting new
trace messages and ignores subsequent requests. The default value is false.
writeToDiagonosticsTrace: If true, all calls to System.Web.UI.Page.Trace.Write
are also forwarded to the System.Diagnostics.Trace.Write and enables us to use
all the standard TraceListeners. The default is false