Asp. NET Tracking mode detailed

Source: Internet
Author: User

"Digest" ASP. NET has a much better tracking function than ASP, and it helps to determine the source of errors in Web applications by tracking information. In this paper, the tracking mode of ASP.net is explained in detail through examples.

"keywords" asp.net; trace information; trace

1. Introduction

The most common debugging method for traditional ASP is to use Response.Write to set breakpoints and to display the values of certain variables on a Web page. However, there are many problems with this approach.

(1) in the program is full of Response.Write statements, these statements may affect debugging, but also affect the layout of the page.

(2) After the commissioning is over, but also painful to delete these statements. And in the removal of redundant Response.Write should be careful to prevent the wrong deletion of the necessary Response.Write statements. If the program has hundreds of lines, the workload can be imagined.

Asp. NET introduces new features that allow you to write debug statements directly in your code, which eliminates the need to remove applications from your application when you deploy them to production servers. This feature, called tracing, allows you to write variables or structures in a page, assert whether a condition is met, or simply trace through the page or application's execution path. To collect and display these messages and other trace information, you must enable tracing for the page or application. When tracing is enabled, two things will happen:

(1) asp.net a series of diagnostic information tables appended to the page output immediately thereafter. The information is also sent to the trace viewer application (only when tracing is enabled for the application).

(2) asp.net displays a custom free clinic break message in the trace information table of the appended performance data. The specified diagnostics and trace messages are appended to the page output sent to the requesting browser. Alternatively, you can view the information in a separate trace viewer (Trace.axd), which displays the trace information for each page in a given application. When ASP.net processing page requests, this information can help you identify errors or do not want to get results.

Trace statements are processed and displayed only after tracing is enabled. You can control whether a trace is displayed on a page, displayed to a trace viewer, or displayed both on the page and in the trace viewer.

2, ASP. NET's tracking mode configuration

In order to be able to use the tracing feature, it is necessary to enable it within the scope of the page or the entire application.

2.1 Page-level configuration

To enable tracing at the page level, you set the trace attribute in the @page directive. As shown below:

*******************************************************************************

<%@ Page language= "vb" Trace= "true" codebehind= "WebForm1.aspx.vb" inherits= "Webapplication1.webform1"%>

*******************************************************************************

Figure 1: Trace Information

If trace has a property value of true, trace information is displayed at the bottom of the page when the page is displayed. Using the TraceMode property allows you to adjust the order in which the information is displayed. TraceMode optional values are: in chronological order (SortByTime) and by category (Sortcategory), where the default value is in chronological order.

2.2 Application-level configuration

There are several options for application-level tracing, which can be set by adding an XML element under in the Config.web file .

Table 1: Tracking options

/tr>
description
enabled > If the trace function is true in the application, Otherwise false
pageoutput
Describes the maximum number of trace requests that the server can hold. The default is 10
tracemode named Displays trace information in some order. by SortByTime (chronological) or by user-defined sortbycategory (alphabetic order). defaults to chronological order.
localonly

*******************************************************************************
<configuration>
<system.web>
<trace Enabled="true" PageOutPut="false" requestLimit="20" traceMode="SortByTime" localOnly="true"/>

</system.web>
</configuration>
*******************************************************************************

Although all properties are used in the example, not every property must be set. and the page-level configuration overrides the application-level configuration. For example, when tracing is disabled at the application level, but it is enabled at the page level, the trace information is still displayed on the page.

The Requstlimit property sets the number of requests that will be recorded in the trace log, which prevents the log from being too large. If the Localonly property is set to True, trace information is only seen on the server. This allows only the server side to track the application while other users do not see trace information.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.