Page.Trace 屬性


取得目前 Web 要求的 TraceContext 物件。Gets the TraceContext object for the current Web request.

 property System::Web::TraceContext ^ Trace { System::Web::TraceContext ^ get(); };
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.



下列程式碼範例將示範如何透過 Trace 屬性來存取 TraceContext.IsEnabled 屬性和 TraceContext.Write 方法。The following code example demonstrates accessing the TraceContext.IsEnabled property and the TraceContext.Write method through the Trace property. 只有在已啟用 Page 物件的追蹤時,此程式碼才會呼叫 Write 方法。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++)
If (Trace.IsEnabled) Then

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

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.