クリックして評価とフィードバックをお寄せください
MSDN
MSDN ライブラリ
.NET 開発
.NET Framework 3.5
.NET Framework 3.5
System.Web 名前空間
HttpApplication クラス
すべて縮小/すべて展開 すべて縮小
このページは次のバージョンについて記述しています。
Microsoft Visual Studio 2008/.NET Framework 3.5

その他のバージョンについては、以下の情報を参照してください。
.NET Framework クラス ライブラリ
HttpApplication クラス

更新 : 2007 年 11 月

ASP.NET アプリケーション内のすべてのアプリケーション オブジェクトに共通のメソッド、プロパティ、およびイベントを定義します。このクラスはアプリケーションの基本クラスで、開発者が Global.asax ファイルで定義します。

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

Visual Basic (宣言)
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class HttpApplication _
    Implements IHttpAsyncHandler, IHttpHandler, IComponent, IDisposable
Visual Basic (使用法)
Dim instance As HttpApplication
C#
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class HttpApplication : IHttpAsyncHandler, 
    IHttpHandler, IComponent, IDisposable
Visual C++
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class HttpApplication : IHttpAsyncHandler, 
    IHttpHandler, IComponent, IDisposable
J#
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal) */
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal) */
public class HttpApplication implements IHttpAsyncHandler, 
    IHttpHandler, IComponent, IDisposable
JScript
public class HttpApplication implements IHttpAsyncHandler, IHttpHandler, IComponent, IDisposable

HttpApplication クラスのインスタンスは、開発者が直接作成するのではなく、ASP.NET インフラストラクチャで作成されます。HttpApplication クラスの 1 つのインスタンスは、その有効期間に多くのリクエストを処理するために使用されます。ただし、1 つのインスタンスは、一度に 1 つの要求しか処理できません。このため、メンバ変数を使用して、要求ごとのデータを格納できます。

アプリケーションは、IHttpModule インターフェイスを実装するカスタム モジュールまたは Global.asax ファイルで定義されているイベント ハンドラ コードによって処理されるイベントを発生させます。IHttpModule インターフェイスを実装するカスタム モジュールは、App_Code フォルダ内または Bin フォルダの DLL 内に格納できます。

HttpApplication は、.NET Framework Version 3.5 で導入されました。詳細については、「.NET Framework 3.5 のアーキテクチャ」を参照してください。

メモ :

統合モードで IIS 7.0 を実行している場合、App_Code フォルダまたは Bin フォルダ内のカスタム モジュールは要求パイプライン内のすべての要求に適用されます。Global.asax ファイル内のイベント ハンドラ コードは、ASP.NET ハンドラにマップされている要求にのみ適用されます。

アプリケーション イベントは、次の順序で発生します。

  1. BeginRequest

  2. AuthenticateRequest

  3. PostAuthenticateRequest

  4. AuthorizeRequest

  5. PostAuthorizeRequest

  6. ResolveRequestCache

  7. PostResolveRequestCache

    PostResolveRequestCache イベントの後および PostMapRequestHandler イベントの前に、イベント ハンドラ (要求 URL に対応するページ) が作成されます。統合モードの IIS 7.0 および .NET Framework Version 3.0 以降を実行しているサーバーでは、MapRequestHandler イベントが発生します。クラシック モードの IIS 7.0 または以前のバージョンの IIS を実行しているサーバーでは、このイベントは処理されません。

  8. PostMapRequestHandler

  9. AcquireRequestState

  10. PostAcquireRequestState

  11. PreRequestHandlerExecute

    イベント ハンドラが実行されます。

  12. PostRequestHandlerExecute

  13. ReleaseRequestState

  14. PostReleaseRequestState

    PostReleaseRequestState イベントの発生後、すべての既存の応答フィルタで出力がフィルタ処理されます。

  15. UpdateRequestCache

  16. PostUpdateRequestCache

  17. LogRequest.

    このイベントは、IIS 7.0 統合モードおよび .NET Framework Version 3.0 以降でサポートされます。

  18. PostLogRequest

    このイベントは、IIS 7.0 統合モードおよび .NET Framework Version 3.0 以降でサポートされます。

  19. EndRequest

HttpApplication クラスとそのイベントの使用方法を次の 2 つの例に示します。最初の例では、カスタム HTTP モジュールを作成してそれにイベントを接続する方法を示します。2 つ目の例では、Web.config ファイルを変更する方法を示します。

カスタム HTTP モジュールを作成し、AcquireRequestState イベントをその HTTP モジュールに接続する方法を次の例に示します。HTTP モジュールが Web アプリケーション リソースへの各要求を受け取ることによって、クライアント要求のフィルタ処理が可能となります。HttpApplication イベントをサブスクライブするすべての HTTP モジュールは、IHttpModule インターフェイスを実装する必要があります。

Visual Basic
Imports System
Imports System.Web

Namespace Samples.AspNet.VB
    Public Class CustomHTTPModule
        Implements IHttpModule

        Public Sub New()

            ' Class constructor.

        End Sub


        ' Classes that inherit IHttpModule 
        ' must implement the Init and Dispose methods.
        Public Sub Init(ByVal app As HttpApplication) Implements IHttpModule.Init

            AddHandler app.AcquireRequestState, AddressOf app_AcquireRequestState
            AddHandler app.PostAcquireRequestState, AddressOf app_PostAcquireRequestState

        End Sub


        Public Sub Dispose() Implements IHttpModule.Dispose

            ' Add code to clean up the
            ' instance variables of a module.

        End Sub


        ' Define a custom AcquireRequestState event handler.
        Public Sub app_AcquireRequestState(ByVal o As Object, ByVal ea As EventArgs)

            Dim httpApp As HttpApplication = CType(o, HttpApplication)
            Dim ctx As HttpContext = HttpContext.Current
            ctx.Response.Write(" Executing AcquireRequestState ")

        End Sub

        ' Define a custom PostAcquireRequestState event handler.
        Public Sub app_PostAcquireRequestState(ByVal o As Object, ByVal ea As EventArgs)

            Dim httpApp As HttpApplication = CType(o, HttpApplication)
            Dim ctx As HttpContext = HttpContext.Current
            ctx.Response.Write(" Executing PostAcquireRequestState ")

        End Sub

    End Class

End Namespace
C#
using System;
using System.Web;

namespace Samples.AspNet.CS
{
    public class CustomHTTPModule : IHttpModule
    {
        public CustomHTTPModule()
        {
            // Class constructor.
        }

        // Classes that inherit IHttpModule 
        // must implement the Init and Dispose methods.
        public void Init(HttpApplication app)
        {

            app.AcquireRequestState += new EventHandler(app_AcquireRequestState);
            app.PostAcquireRequestState += new EventHandler(app_PostAcquireRequestState);
        }

        public void Dispose()
        {
            // Add code to clean up the
            // instance variables of a module.
        }

        // Define a custom AcquireRequestState event handler.
        public void app_AcquireRequestState(object o, EventArgs ea)
        {
            HttpApplication httpApp = (HttpApplication)o;
            HttpContext ctx = HttpContext.Current;
            ctx.Response.Write(" Executing AcquireRequestState ");
        }

        // Define a custom PostAcquireRequestState event handler.
        public void app_PostAcquireRequestState(object o, EventArgs ea)
        {
            HttpApplication httpApp = (HttpApplication)o;
            HttpContext ctx = HttpContext.Current;
            ctx.Response.Write(" Executing PostAcquireRequestState ");
        }

    }
}

カスタム HTTP モジュール内でイベントを発生させるには、HTTP モジュールに関する通知が ASP.NET に対して行われるように、Web.config ファイルで構成設定を変更する必要があります。Web.config ファイルの httpModules セクションにおける適切な構成設定を次の例に示します。次の設定は、IIS 7.0 クラシック モードおよび以前のバージョンの IIS に適用されます。

C#
<configuration>
  <system.web>
    <httpModules>
      <add type="Samples.AspNet.CS.CustomHTTPModule"
        name="CustomHttpModule" />
      </httpModules>
  </system.web>
</configuration>
Visual Basic
<configuration>
  <system.web>
    <httpModules>
      <add type="Samples.AspNet.VB.CustomHTTPModule"
        name="CustomHttpModule" />
      </httpModules>
  </system.web>
</configuration>

次の設定は、IIS 7.0 統合モードに適用されます。

C#
<configuration>
  <system.webServer>
    <modules>
      <add type="Samples.AspNet.CS.CustomHTTPModule"
        name="CustomHttpModule" />
      </modules>
  </system.webServer>
</configuration>
Visual Basic
<configuration>
  <system.webServer>
    <modules>
      <add type="Samples.AspNet.VB.CustomHTTPModule"
        name="CustomHttpModule" />
      <modules>
  </system.webServer>
</configuration>
System..::.Object
  System.Web..::.HttpApplication
この型のすべてのパブリック static (Visual Basic では Shared) メンバは、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

.NET Framework および .NET Compact Framework では、各プラットフォームのすべてのバージョンはサポートしていません。サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。

.NET Framework

サポート対象 : 3.5、3.0、2.0、1.1、1.0
コミュニティ コンテンツ   コミュニティ コンテンツとは
新しいコンテンツの追加 RSS  注釈
Processing
© 2009 Microsoft Corporation. All rights reserved. 使用条件 | 商標 | プライバシー
Page view tracker