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透過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" %>. 若要啟用整個應用程式的追蹤,您必須在應用程式的設定檔 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.

適用於

另請參閱