HttpContextとは? わかりやすく解説

HttpContext クラス

それぞれの HTTP 要求に関する HTTP 固有のすべての情報カプセル化ます。

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

Public NotInheritable Class
 HttpContext
    Implements IServiceProvider
public sealed class HttpContext : IServiceProvider
public ref class HttpContext sealed : IServiceProvider
public final class HttpContext implements IServiceProvider
public final class HttpContext implements IServiceProvider
解説解説
使用例使用例

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.Object
  System.Web.HttpContext
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
HttpContext メンバ
System.Web 名前空間
IHttpModule
IHttpHandler

HttpContext コンストラクタ (HttpWorkerRequest)


HttpContext コンストラクタ (HttpRequest, HttpResponse)

指定した要求オブジェクト応答オブジェクト使用して、HttpContext クラス新しインスタンス初期化します。

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

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

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 クラス
System.Web 名前空間
IHttpModule
IHttpHandler

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 から継承されます。)
プロテクト メソッドプロテクト メソッド
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 System.IServiceProvider.GetService 現在のサービス型のオブジェクト返します
参照参照

関連項目

HttpContext クラス
System.Web 名前空間
IHttpModule
IHttpHandler

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 から継承されます。)
プロテクト メソッドプロテクト メソッド
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 System.IServiceProvider.GetService 現在のサービス型のオブジェクト返します
参照参照

関連項目

HttpContext クラス
System.Web 名前空間
IHttpModule
IHttpHandler


このページでは「.NET Framework クラス ライブラリ リファレンス」からHttpContextを検索した結果を表示しています。
Weblioに収録されているすべての辞書からHttpContextを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からHttpContextを検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「HttpContext」の関連用語

HttpContextのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



HttpContextのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS