SIGN UP MEMBER LOGIN:    
ARTICLE

Page Tracing in ASP.NET 4.0

Posted by Prabhu Raja Articles | ASP.NET Programming December 20, 2011
Visual Studio debugging tools and ASP.NET detailed error pages are very helpful when we have testing a web application. But, sometimes we need a way to identify problems after we have deployed the application, while we don’t have Visual Studio IDE on that Computer.
Reader Level:
Download Files:
 

Visual Studio debugging tools and ASP.NET detailed error pages are very helpful when we have testing a web application. But, sometimes we need a way to identify problems after we have deployed the application, while we don't have Visual Studio IDE on that Computer.

We can identify these errors by recording diagnostic information in an event log, but this assumes that someone will actually review the log regularly. Moreover, we could display some information directly in the web page. The problem with this strategy is that we need to remove (or comment out) all this extra code before we deploy the web application. Otherwise, the website users could see some strange debugging messages when they don't expect it.

Fortunately, there is an easier way to solve this problem. The ASP.NET provides a feature called tracing that gives a convenient and flexible way to report diagnostic information's.

Enabling Tracing:

To use tracing, we need to explicitly enable it. There are several ways to enable tracing. One of the easiest ways is by adding an attribute to the Page directive in the .aspx file:

<%@ Page Trace="true" ... %>

We can also enable tracing using the built-in Trace object. Here's an example of how to turn on tracing in the Page. Load event handler:

using System.Web;
protected void Page_Load(Object sender, EventArgs e)
{
Trace.IsEnabled = true; // (Trace is an instance of the System.Web.TraceContext class)
}

By default, once the tracing is enabled, it will apply only to local requests. This limitation prevents end users from seeing the tracing information. If we need to trace a web page from a remote location, we have to enable remote tracing by changing some settings in the web.config file.

Tracing Information:

ASP.NET tracing automatically provides a lengthy set of standard, formatted information. The following example shows what this information looks like. To build this example, we can start with basic ASP.NET page as shown here,

Tracking1.jpg

This page displaying only a single line of text and a Button. If we click the button, tracing is enabled by setting the Trace.IsEnabled property to true as shown in the Code Snippet above. When the page is rendered, it will include a standard and formatted diagnostic information's, as shown below.

Tracking2.jpg

Tracing information is provided in several different categories, as Request Details, Trace Information, Control Tree, Session State and Application State, Request Cookies and Response Cookies, Headers Collection, Form Collection, Query String Collection and Server Variables.

Application-Level Tracing:

Application-level tracing allow to enable tracing for an entire application and the tracing information won't be displayed in the page. Instead, it will be collected and stored in memory for a short amount of time. We can review the recently traced information by requesting a special URL.
To enable application-level tracing, we need to modify settings in the web.config file, as

<configuration>
<system.web>
<trace enabled="true" requestLimit="10" pageOutput="false" />
</system.web>
</configuration>

Tracing Options:

Attribute Values Description
Enabled True, False Turns application-level tracing on or off.
requestLimit Any integer Stores tracing information for a maximum number of HTTP requests.
pageOutput true, false Determines whether tracing information will be displayed on the page.
traceMode SortByTime, SortByCategory Determines the sort order of trace messages. The default is SortByTime.
localOnly true, false Determines whether tracing information will be shown only to
local clients (clients using the same computer) or can be shown to
remote clients as well. By default, this is true and remote clients
cannot see tracing information.
mostRecent true, false Keeps only the most recent trace messages if true. When the requestLimit maximum is reached, the information for the oldest request is abandoned every time a new request is received. If false (the default), ASP.NET stops collecting new trace messages when the limit is reached.

To view tracing information, we have to request the trace.axd file in the web application's root directory. This file is actually doesn't exist, the ASP.NET automatically interprets it as a request for the tracing information. It will then list the most recent collected requests, as Shown below.

Tracking3.jpg

Thank You.
 

Login to add your contents and source code to this article
share this article :
post comment
 

I am really happy with your Comments. Thank You So much.

Posted by Prabhu Raja Dec 22, 2011

Great work. I will surely implement it today itself. Thanks for sharing it.

Posted by Monika Arora Dec 22, 2011

Good article Mr. Raja

Posted by Akash Ahlawat Dec 21, 2011

Good topic for making articles

Posted by Alec Stewart Dec 21, 2011

very good article

Posted by Jimmy Underwood Dec 21, 2011
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Become a Sponsor