次の方法で共有


Page.Context プロパティ

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

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)

構文

'宣言
Protected Friend Overrides ReadOnly Property Context As HttpContext
'使用
Dim value As HttpContext

value = Me.Context
protected internal override HttpContext Context { get; }
protected public:
virtual property HttpContext^ Context {
    HttpContext^ get () override;
}
/** @property */
protected HttpContext get_Context ()
protected internal override function get Context () : HttpContext
適用できません。

プロパティ値

現在のページに関連付けられた情報が格納されている HttpContext オブジェクト。

解説

このプロパティを使用すると、要求、応答、セッション、およびアプリケーションに関する情報を含め、ページが実行されているコンテキストにプログラムによってアクセスできます。

使用例

Context プロパティを使用して、System.Web.HttpContext.AddError(System.Exception) メソッド、System.Web.HttpContext.ClearError メソッド、および System.Web.HttpContext.AllErrors プロパティにアクセスするコード例を次に示します。この例では AddError メソッドを使用して、3 つの独自の例外を作成し、AllErrors プロパティを使用してそれらの例外を配列に読み込みます。次に、配置先のページにその配列を書き込み、ClearError メソッドを使用してすべてのエラーを Context プロパティから削除します。

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
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();
}
void Page_Load(Object sender,System.EventArgs e) 
{
    get_Response().Write("<h3>Page.Context Example:</h3>");

    // Add three custom exceptions.
    get_Context().AddError(new Exception
        ("<h3 style=\"color: red\">New Exception #1.</h3>"));
    get_Context().AddError(new Exception
        ("<h3 style=\"color: red\">New Exception #2.</h3>"));
    get_Context().AddError(new Exception
        ("<h3 style=\"color: red\">New Exception #3.</h3>"));
 
    // Capture all the new Exceptions in an array.
    System.Exception errs[] = get_Context().get_AllErrors();
 
    for (int iCtr=0;iCtr<errs.length;iCtr++) 
    {
        System.Exception ex = errs[iCtr];
        get_Response().Write("<p style='text-align: center; " 
            + "font-weight: bold'>"
            + get_Server().HtmlEncode(ex.ToString())
            + "</p>");
    }
    // Clear the exceptions so ASP.NET won't handle them.
    get_Context().ClearError();
}//Page_Load

プラットフォーム

Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition

Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。

バージョン情報

.NET Framework

サポート対象 : 3.0,2.0,1.1,1.0

参照

関連項目

Page クラス
Page メンバ
System.Web.UI 名前空間
HttpContext