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


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

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

辞書ショートカット

すべての辞書の索引

「HttpContext クラス」の関連用語

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

   

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



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

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

©2025 GRAS Group, Inc.RSS