Free Web Development Online Tutorials, Learn to Code
Learn Asp.net Aspx, Free Asp.net Tutorial in C#, Asp.net Web Application Development Guide

How to use Tracing in Asp.net

Tracing in Asp.net allows you to see diagnostic information about a page request. Tracing enables you to view a page's execution cycle, display diagnostic information at run time, and debug your application.

There are two ways you can enable Tracing in Asp.net:

  • Page Level Tracing
  • Application Level Tracing
Tracing is disabled by default in an ASP.NET application.

If you enable tracing, ASP.NET will append a series of execution details about the page request at the bottom of the page.

Page Level Tracing

To enable tracing in your asp.net page simply add Trace="true" TraceMode="SortByCategory" in your page directive

            <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
     CodeBehind="Default.aspx.cs" Inherits="WTRWebForm._Default" Trace="true" TraceMode="SortByCategory" %>

TraceMode is optional, ="Default | SortByCategory | SortByTime"

After enabling Trace on your page, simply page F5 to refresh the page, you will be able to see the list of tables appearing with following headers.

  • Request Details
  • Trace Information
  • Control Tree
  • Session State
  • Application State
  • Request Cookies Collection
  • Response Cookies Collection
  • Headers Collection
  • Response Headers Collection
  • Form Collection
  • Querystring Collection
  • Server Variables

Application Level Tracing

Instead of enabling tracing for one particular page, you also can enable tracing for entire application. If you do that, every page in your application will display the trace information.

To understand the impact of application level tracing let’s remove the page level tracing first.

Now, open your web.config file and add the following <trace /> tag inside the system.web tag

<system.web>
<trace enabled="true" pageOutput="true" requestLimit="30" localOnly="false"/>
</system.web>

Now if you check all the pages in your application has been trace enabled
Notice, there are few additional parameters in above trace tag.

parameter description
PageOutput Default is false. If true then it will display trace both in pages and in the trace viewer (trace.axd)
RequestLimit Default is 10, Indicate the number of trace requests to store on server
LocalOnly Default is true, if true then the trace viewer (trace.axd) available only on the host Web server

Comment
Name
Email
Website
Subscribe
 
Tracing in Asp.net Application