HttpContext クラス
アセンブリ: System.Web (system.web.dll 内)


IHttpModule インターフェイスおよび IHttpHandler インターフェイスを継承するクラスには、現在の HTTP 要求の HttpContext オブジェクトへの参照が用意されています。このオブジェクトは、要求に組み込まれる Request、Response、および Server 各プロパティへのアクセスを実現します。

HttpContext オブジェクトのプロパティにアクセスして表示する方法を次のコード例に示します。現在の HTTP 要求のコンテキストにアクセスするには、Page オブジェクトの Context プロパティを使用します。
<%@ Page Language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) ' The HttpContext associated with the page can be accessed by the Context property. Dim sb As New System.Text.StringBuilder() ' Use the current HttpContext object to determine if custom errors are enabled. sb.Append("Is custom errors enabled: " & _ Context.IsCustomErrorEnabled.ToString() & "<br/>") ' Use the current HttpContext object to determine if debugging is enabled. sb.Append("Is debugging enabled: " & _ Context.IsDebuggingEnabled.ToString() & "<br/>") ' Use the current HttpContext object to access the current TraceContext object. sb.Append("Trace Enabled: " & _ Context.Trace.IsEnabled.ToString() & "<br/>") ' Use the current HttpContext object to access the current HttpApplicationState object. sb.Append("Number of items in Application state: " & _ Context.Application.Count.ToString() & "<br/>") ' Use the current HttpContext object to access the current HttpSessionState object. ' Session state may not be configured. Try sb.Append("Number of items in Session state: " & _ Context.Session.Count.ToString() & "<br/>") Catch ex As Exception sb.Append("Session state not enabled. <br/>") End Try ' Use the current HttpContext object to access the current Cache object. sb.Append("Number of items in the cache: " & _ Context.Cache.Count.ToString() & "<br/>") ' Use the current HttpContext object to determine the timestamp for the current HTTP Request. sb.Append("Timestamp for the HTTP request: " & _ Context.Timestamp.ToString() & "<br/>") ' Assign StringBuilder object to output label. OutputLabel.Text = sb.ToString() End Sub </script> <html > <head runat="server"> <title>HttpContext Example</title> </head> <body> <form id="form1" runat="server"> <div> Using the current HttpContext to get information about the current page. <br /> <asp:Label id="OutputLabel" runat="server"></asp:Label> </div> </form> </body> </html>
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { // The HttpContext associated with the page can be accessed by the Context property. System.Text.StringBuilder sb = new System.Text.StringBuilder(); // Use the current HttpContext object to determine if custom errors are enabled. sb.Append("Is custom errors enabled: " + Context.IsCustomErrorEnabled.ToString() + "<br/>"); // Use the current HttpContext object to determine if debugging is enabled. sb.Append("Is debugging enabled: " + Context.IsDebuggingEnabled.ToString() + "<br/>"); // Use the current HttpContext object to access the current TraceContext object. sb.Append("Trace Enabled: " + Context.Trace.IsEnabled.ToString() + "<br/>"); // Use the current HttpContext object to access the current HttpApplicationState object. sb.Append("Number of items in Application state: " + Context.Application.Count.ToString() + "<br/>"); // Use the current HttpContext object to access the current HttpSessionState object. // Session state may not be configured. try { sb.Append("Number of items in Session state: " + Context.Session.Count.ToString() + "<br/>"); } catch { sb.Append("Session state not enabled. <br/>"); } // Use the current HttpContext object to access the current Cache object. sb.Append("Number of items in the cache: " + Context.Cache.Count.ToString() + "<br/>"); // Use the current HttpContext object to determine the timestamp for the current HTTP Request. sb.Append("Timestamp for the HTTP request: " + Context.Timestamp.ToString() + "<br/>"); // Assign StringBuilder object to output label. OutputLabel.Text = sb.ToString(); } </script> <html > <head runat="server"> <title>HttpContext Example</title> </head> <body> <form id="form1" runat="server"> <div> Using the current HttpContext to get information about the current page. <br /> <asp:Label id="OutputLabel" runat="server"></asp:Label> </div> </form> </body> </html>

System.Web.HttpContext


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


HttpContext コンストラクタ (HttpWorkerRequest)
アセンブリ: System.Web (system.web.dll 内)


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


HttpContext コンストラクタ (HttpRequest, HttpResponse)
アセンブリ: System.Web (system.web.dll 内)

Dim request As HttpRequest Dim response As HttpResponse Dim instance As New HttpContext(request, response)
public HttpContext ( HttpRequest request, HttpResponse response )
public: HttpContext ( HttpRequest^ request, HttpResponse^ response )
public HttpContext ( HttpRequest request, HttpResponse response )

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


HttpContext コンストラクタ

名前 | 説明 |
---|---|
HttpContext (HttpWorkerRequest) | 指定したワーカー要求オブジェクトを使用して、HttpContext クラスの新しいインスタンスを初期化します。 |
HttpContext (HttpRequest, HttpResponse) | 指定した要求オブジェクトと応答オブジェクトを使用して、HttpContext クラスの新しいインスタンスを初期化します。 |

HttpContext プロパティ

名前 | 説明 | |
---|---|---|
![]() | CurrentHandler | 現在実行中のハンドラを表す IHttpHandler オブジェクトを取得します。 |
![]() | Error | HTTP 要求の処理中にエラーが蓄積された場合は、その最初のエラーを取得します。 |
![]() | Handler | HTTP 要求の処理を実行する IHttpHandler オブジェクトを取得または設定します。 |
![]() | IsCustomErrorEnabled | 現在の HTTP 要求に対してカスタム エラーが有効かどうかを示す値を取得します。 |
![]() | IsDebuggingEnabled | 現在の HTTP 要求がデバッグ モードかどうかを示す値を取得します。 |
![]() | Items | HTTP 要求時に IHttpModule インターフェイスと IHttpHandler インターフェイスとの間でデータを編成および共有するために使用できるキー/値のコレクションを取得します。 |
![]() | PreviousHandler | 親ハンドラの IHttpHandler オブジェクトを取得します。 |
![]() | Profile | 現在のユーザー プロファイルの ProfileBase オブジェクトを取得します。 |
![]() | Request | 現在の HTTP 要求に対する HttpRequest オブジェクトを取得します。 |
![]() | Response | 現在の HTTP 応答に対する HttpResponse オブジェクトを取得します。 |
![]() | Server | Web 要求の処理で使用されるメソッドを提供する HttpServerUtility オブジェクトを取得します。 |
![]() | Session | 現在の HTTP 要求に対する HttpSessionState オブジェクトを取得します。 |
![]() | SkipAuthorization | UrlAuthorizationModule オブジェクトが現在の要求に対する承認チェックをスキップするかどうかを指定する値を取得または設定します。 |
![]() | Timestamp | 現在の HTTP 要求の初期タイムスタンプを取得します。 |
![]() | Trace | 現在の HTTP 応答に対する TraceContext オブジェクトを取得します。 |
![]() | User | 現在の HTTP 要求のセキュリティ情報を取得または設定します。 |

HttpContext メソッド

名前 | 説明 | |
---|---|---|
![]() | AddError | 現在の HTTP 要求の例外コレクションに例外を追加します。 |
![]() | ClearError | 現在の HTTP 要求に対するすべてのエラーをクリアします。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetAppConfig | 現在のアプリケーションに対して要求された構成情報を返します。 |
![]() | GetConfig | 現在の HTTP 要求に対して要求された構成情報を返します。 |
![]() | GetGlobalResourceObject | オーバーロードされます。 アプリケーション レベル リソースを取得します。 |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetLocalResourceObject | オーバーロードされます。 ページ レベル リソースを取得します。 |
![]() | GetSection | 現在のアプリケーションの既定構成の、指定した構成セクションを取得します。 |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | RewritePath | オーバーロードされます。 内部リライト パスを割り当てます。これにより、要求された URL とは異なる内部パスのリソースを示すことができます。RewritePath は Cookie なしのセッション状態で使用されます。 |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |


HttpContext メンバ
それぞれの HTTP 要求に関する HTTP 固有のすべての情報をカプセル化します。
HttpContext データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | CurrentHandler | 現在実行中のハンドラを表す IHttpHandler オブジェクトを取得します。 |
![]() | Error | HTTP 要求の処理中にエラーが蓄積された場合は、その最初のエラーを取得します。 |
![]() | Handler | HTTP 要求の処理を実行する IHttpHandler オブジェクトを取得または設定します。 |
![]() | IsCustomErrorEnabled | 現在の HTTP 要求に対してカスタム エラーが有効かどうかを示す値を取得します。 |
![]() | IsDebuggingEnabled | 現在の HTTP 要求がデバッグ モードかどうかを示す値を取得します。 |
![]() | Items | HTTP 要求時に IHttpModule インターフェイスと IHttpHandler インターフェイスとの間でデータを編成および共有するために使用できるキー/値のコレクションを取得します。 |
![]() | PreviousHandler | 親ハンドラの IHttpHandler オブジェクトを取得します。 |
![]() | Profile | 現在のユーザー プロファイルの ProfileBase オブジェクトを取得します。 |
![]() | Request | 現在の HTTP 要求に対する HttpRequest オブジェクトを取得します。 |
![]() | Response | 現在の HTTP 応答に対する HttpResponse オブジェクトを取得します。 |
![]() | Server | Web 要求の処理で使用されるメソッドを提供する HttpServerUtility オブジェクトを取得します。 |
![]() | Session | 現在の HTTP 要求に対する HttpSessionState オブジェクトを取得します。 |
![]() | SkipAuthorization | UrlAuthorizationModule オブジェクトが現在の要求に対する承認チェックをスキップするかどうかを指定する値を取得または設定します。 |
![]() | Timestamp | 現在の HTTP 要求の初期タイムスタンプを取得します。 |
![]() | Trace | 現在の HTTP 応答に対する TraceContext オブジェクトを取得します。 |
![]() | User | 現在の HTTP 要求のセキュリティ情報を取得または設定します。 |

名前 | 説明 | |
---|---|---|
![]() | AddError | 現在の HTTP 要求の例外コレクションに例外を追加します。 |
![]() | ClearError | 現在の HTTP 要求に対するすべてのエラーをクリアします。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetAppConfig | 現在のアプリケーションに対して要求された構成情報を返します。 |
![]() | GetConfig | 現在の HTTP 要求に対して要求された構成情報を返します。 |
![]() | GetGlobalResourceObject | オーバーロードされます。 アプリケーション レベル リソースを取得します。 |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetLocalResourceObject | オーバーロードされます。 ページ レベル リソースを取得します。 |
![]() | GetSection | 現在のアプリケーションの既定構成の、指定した構成セクションを取得します。 |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | RewritePath | オーバーロードされます。 内部リライト パスを割り当てます。これにより、要求された URL とは異なる内部パスのリソースを示すことができます。RewritePath は Cookie なしのセッション状態で使用されます。 |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |


Weblioに収録されているすべての辞書からHttpContextを検索する場合は、下記のリンクをクリックしてください。

- HttpContextのページへのリンク