Language

Page.Context プロパティ

定義

ページに関連付けられている HttpContext オブジェクトを取得します。

protected:
 virtual property System::Web::HttpContext ^ Context { System::Web::HttpContext ^ get(); };
protected public:
 virtual property System::Web::HttpContext ^ Context { System::Web::HttpContext ^ get(); };
protected override System.Web.HttpContext Context { get; }
protected internal override System.Web.HttpContext Context { get; }
member this.Context : System.Web.HttpContext
Protected Overrides ReadOnly Property Context As HttpContext
Protected Friend Overrides ReadOnly Property Context As HttpContext

プロパティ値

現在のページに関連付けられている情報を含む HttpContext オブジェクト。

例

次のコード例では、 Context プロパティを使用して、 HttpContext.AddError メソッドと HttpContext.ClearError メソッド、および HttpContext.AllErrors プロパティにアクセスします。 この例では、 AddError メソッドを使用して 3 つのカスタム例外を作成し、 AllErrors プロパティを使用してこれらの例外を配列に読み込みます。 次に、配列を含むページに書き込み、 ClearError メソッドを使用して、 Context プロパティからすべてのエラーをクリアします。

     void Page_Load(Object sender,EventArgs e) 
     {
        Response.Write("<h3>Page.Context Example:</h3>");

        // Add three custom exceptions.
        Context.AddError(new Exception(
            "<h3 style='color: red'>New Exception #1.</h3>"));
        Context.AddError(new Exception(
            "<h3 style='color: red'>New Exception #2.</h3>"));
        Context.AddError(new Exception(
            "<h3 style='color: red'>New Exception #3.</h3>"));

        // Capture all the new Exceptions in an array.
        Exception[] errs = Context.AllErrors;

        foreach (Exception ex in errs)
        {
           Response.Write("<p style='text-align:center; ");
           Response.Write("font-weight:bold'>");
           Response.Write(Server.HtmlEncode(ex.ToString()) + "</p>"); 
        }

        // Clear the exceptions so ASP.NET won't handle them.
        Context.ClearError();
     }

     Sub Page_Load(Sender As Object, e As EventArgs ) 
     
        Response.Write("<h3>Page.Context Example:</h3>")
           
        ' Add three custom exceptions.
       Context.AddError(New Exception( _
           "<h3 style=""color: red"">New Exception #1.</h3>"))
       Context.AddError(New Exception( _
           "<h3 style=""color: red"">New Exception #2.</h3>"))
       Context.AddError(New Exception( _
           "<h3 style=""color: red"">New Exception #3.</h3>"))

        ' Capture all the new Exceptions in an array.
        Dim errs() As Exception = Context.AllErrors
        Dim ex As Exception
        
        For Each ex In errs
           Response.Write("<p style='text-align:center; font-weight:bold'>")
           Response.Write(Server.HtmlEncode(ex.ToString()) + "</p>")
        Next

        ' Clear the exceptions so ASP.NET won't handle them.
        Context.ClearError()
     End Sub

注釈

このプロパティは、要求、応答、セッション、アプリケーションに関する情報など、ページが実行されるコンテキストへのプログラムによるアクセスを提供します。

適用対象

こちらもご覧ください