Page.Trace Page.Trace Page.Trace Page.Trace Property

定义

为当前 Web 请求获取 TraceContext 对象。Gets the TraceContext object for the current Web request.

public:
 property System::Web::TraceContext ^ Trace { System::Web::TraceContext ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Web.TraceContext Trace { get; }
member this.Trace : System.Web.TraceContext
Public ReadOnly Property Trace As TraceContext

属性值

来自当前 Web 请求的 TraceContext 对象的数据。Data from the TraceContext object for the current Web request.

示例

下面的代码示例演示如何通过TraceContext.IsEnabled Trace属性访问属性TraceContext.Write和方法。The following code example demonstrates accessing the TraceContext.IsEnabled property and the TraceContext.Write method through the Trace property. 此代码仅在Write Page为对象启用跟踪时才调用方法。This code calls the Write method only when tracing is enabled for the Page object. 如果未启用,则不会运行此代码,这有助于降低应用程序的系统开销。If it is not enabled, this code will not run, which can help reduce overhead for your application.

if (Trace.IsEnabled)
{
  for (int i=0; i<ds.Tables["Categories"].Rows.Count; i++)
  {
    Trace.Write("ProductCategory",ds.Tables["Categories"].Rows[i][0].ToString());
  }
}
If (Trace.IsEnabled) Then

  Dim I As Integer
  For I = 0 To DS.Tables("Categories").Rows.Count - 1

    Trace.Write("ProductCategory",DS.Tables("Categories").Rows(I)(0).ToString())
  Next
End If

注解

跟踪跟踪并显示有关 Web 请求的执行详细信息。Tracing tracks and presents the execution details about a Web request. 要使跟踪数据在呈现的页中可见,必须在页面或应用程序级别启用跟踪。For trace data to be visible in a rendered page, you must enable tracing at the page or application level.

默认情况下,禁用对页面的跟踪。Tracing on a page is disabled by default. 若要为页面启用跟踪,请使用@ page指令<% @ Page trace="true" %>To enable tracing for a page, use the @ Page directive <% @ Page trace="true" %>. 若要为整个应用程序启用跟踪,必须在应用程序的配置文件(位于应用程序的根目录中)中启用跟踪。To enable tracing for an entire application, you must enable it in the application's configuration file, Web.config, which resides in the root directory of the application. 有关详细信息,请参阅ASP.NET 跟踪概述For more information, see ASP.NET Tracing Overview.

适用于

另请参阅