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

屬性值

TraceContext 物件而來的資料,提供給目前的 Web 要求。Data from the TraceContext object for the current Web request.

範例

下列程式碼範例將示範如何存取TraceContext.IsEnabled屬性和TraceContext.Write方法,透過Trace屬性。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" %>. 若要啟用整個應用程式的追蹤,您必須在應用程式的組態檔,位於應用程式的根目錄的 Web.config 中啟用它。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.

適用於

另請參閱