ISAPI フィルター: <isapiFilters>

概要

<isapiFilters> 要素を使うと、インターネット インフォメーション サービス (IIS) 7 サーバーで ISAPI フィルターを管理できます。 Web サーバーの機能を強化したいときに、ISAPI フィルターを追加できます。 たとえば、HTTP 要求に関する情報をキャプチャし、その情報をデータベースに保存する ISAPI フィルターといったものです。

Note

IIS 7 では ISAPI フィルターがサポートされていますが、Web サーバーの機能を拡張するには ISAPI フィルターではなくモジュールを使うことをお勧めします。

<isapiFilters> 要素には 1 つ以上の <filter> 要素を含めることができ、それぞれでサーバーまたは Web サイトに対して有効な ISAPI フィルターを定義します。 また、<remove> 要素を含めることもでき、それを使って、構成階層の上位から継承された特定の ISAPI フィルターを削除できます。 <isapiFilters> 要素には <clear> 要素を含めることもでき、これにより、構成階層の上位から継承されたすべての ISAPI フィルターが削除されます。

互換性

バージョン メモ
IIS 10.0 <isapiFilters> 要素は、IIS 10.0 では変更されませんでした。
IIS 8.5 <isapiFilters> 要素は、IIS 8.5 では変更されませんでした。
IIS 8.0 <isapiFilters> 要素は、IIS 8.0 では変更されませんでした。
IIS 7.5 <isapiFilters> 要素は、IIS 7.5 では変更されませんでした。
IIS 7.0 <isapiFilters> 要素は IIS 7.0 で導入されました。
IIS 6.0 <isapiFilters> 要素は、IIS 6.0 の FilterEnableCacheFilterPath メタベース プロパティを置き換えます。

段取り

<isapiFilters> 要素を使うには、IIS 7 以降のサーバーに ISAPI フィルター モジュールをインストールする必要があります。 そのためには、次のステップに従います。

Windows Server 2012 または Windows Server 2012 R2

  1. タスク バーで [サーバー マネージャー]をクリックします。
  2. [サーバー マネージャー] で、[管理] メニューをクリックし、[役割と機能の追加] をクリックします。
  3. 役割と機能の追加ウィザードで、[次へ] をクリックします。 インストールの種類を選択し、[次へ] をクリックします。 対象サーバーを選択し、[次へ] をクリックします。
  4. [サーバーの役割] ページで、[Web サーバー (IIS)][Web サーバー][アプリケーション開発] の順に展開して、[ISAPI フィルター] を選びます。 次へ をクリックします。
    Screenshot of I S A P I Filters selected in a Windows Server 2012 Interface.
  5. [機能の選択] ページで、[次へ] をクリックします。
  6. [インストール オプションの確認] ページで、[インストール] をクリックします。
  7. [結果] ページで、 [閉じる]をクリックします。

Windows 8 または Windows 8.1

  1. [スタート] 画面で、ポインターを左下隅まで移動し、[スタート] ボタンを右クリックし、[コントロール パネル] をクリックします。
  2. [コントロール パネル][プログラムと機能] をクリックし、[Windows の機能の有効化または無効化] をクリックします。
  3. [インターネット インフォメーション サービス][World Wide Web サービス][アプリケーション開発機能] の順に展開して、[ISAPI フィルター] を選択します。
    Screenshot of I S A P I Filters selected in a Windows 8 interface.
  4. OK をクリックします。
  5. 閉じるをクリックします。

Windows Server 2008 または Windows Server 2008 R2

  1. タスク バーの [スタート] をクリックし、[管理ツール] をポイントして、[サーバー マネージャー] をクリックします。
  2. [サーバー マネージャー] 階層ウィンドウで [役割] を展開し、[Web サーバー (IIS)] をクリックします。
  3. [Web サーバー (IIS)] ウィンドウで、[役割サービス] セクションまでスクロールし、[役割サービスの追加] をクリックします。
  4. 役割サービスの追加ウィザード[役割サービスの選択] ページで、[ISAPI フィルター] を選択し、[次へ] をクリックします。
    Screenshot of I S A P I Filters selected in a Windows Server 2008 interface.
  5. [インストール オプションの確認] ページで、[インストール] をクリックします。
  6. [結果] ページで、 [閉じる]をクリックします。

Windows Vista または Windows 7

  1. タスク バーで、[スタート][コントロール パネル] の順にクリックします。
  2. [コントロール パネル][プログラムと機能] をクリックし、[Windows の機能の有効化または無効化] をクリックします。
  3. [Windows 機能] ダイアログ ボックスで、[インターネット インフォメーション サービス][World Wide Web サービス][アプリケーション開発機能] の順に展開します。
    Screenshot of I S A P I Filters selected in a Windows Vista or Windows 7 interface.
  4. [ISAPI フィルター] を選んで、[OK] をクリックします。

操作方法

ISAPI フィルターを追加する方法

  1. インターネット インフォメーション サービス (IIS) マネージャーを開きます。

    • Windows Server 2012 または Windows Server 2012 R2 を使用している場合:

      • タスク バーで、[サーバー マネージャー][ツール][インターネット インフォメーション サービス (IIS) マネージャー] の順にクリックします。
    • Windows 8 または Windows 8.1 を使用している場合:

      • Windows キーを押しながら文字 X を押し、[コントロール パネル] をクリックします。
      • [管理ツール] をクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
    • Windows Server 2008 または Windows Server 2008 R2 を使用している場合:

      • タスク バーの [スタート] をクリックし、[管理ツール] をポイントして、[インターネット インフォメーション サービス (IIS) マネージャー] をクリックします。
    • Windows Vista または Windows 7 を使用している場合:

      • タスク バーで、[スタート][コントロール パネル] の順にクリックします。
      • [管理ツール] をダブルクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
  2. [接続] ウィンドウで、ISAPI フィルターを構成する接続またはサイトに移動します。

  3. [ホーム] ウィンドウで、[ISAPI フィルター] をダブルクリックします。
    Screenshot of I S A P I Filters selected in the Default Web Site Home pane.

  4. [操作] ウィンドウで、[追加] をクリックします。

  5. [ISAPI フィルターの追加] ダイアログ ボックスの [フィルター名] テキスト ボックスに、ISAPI フィルターのフレンドリ名を入力します。

  6. [実行可能ファイル] ボックスに、ISAPI フィルター ファイルの場所のファイル システム パスを入力するか、省略記号 ([...]) をクリックして ISAPI フィルター ファイルを含むフォルダーに移動して、[OK] をクリックします。
    Screenshot of a blank Add I S A P I Filter dialog.

構成

ISAPI フィルターは、サーバー レベルとサイト レベルで追加できます。 ISAPI フィルターをサーバー レベルで追加すると、サーバーに対して行われたすべての要求がフィルターによってインターセプトされます。 ISAPI フィルターを特定のサイトに追加すると、そのサイトに対して行われたすべての要求がフィルターによってインターセプトされます。

<isapiFilters> 要素は、ApplicationHost.config ファイルを使ってサーバー レベルで、または適切な Web.config ファイルを使ってサイト レベルで構成できます。

属性

なし。

子要素

要素 説明
clear 省略可能な要素です。

ISAPI フィルター コレクションから、ISAPI フィルターへのすべての参照を削除します。
filter 省略可能な要素です。

ISAPI フィルター コレクションに、ISAPI フィルターを追加します。
remove 省略可能な要素です。

ISAPI フィルター コレクションから、1 つの ISAPI フィルターへの参照を削除します。

構成サンプル

次の構成例では、SalesQueryIsapi という名前の ISAPI フィルターを Web サイトまたはアプリケーションに追加します。 サンプルでは、nameenabled 属性を使って、ISAPI フィルターの名前を指定し、有効にしています。 また、enableCache 属性を使って HTTP.sys キャッシュを無効にし、path 属性を使って ISAPI DLL の場所を指定しています。

<configuration>
   <system.webServer>
      <isapiFilters>
         <filter 
            name="SalesFilter" 
            enabled="true" 
            enableCache="false" 
            path="C:\Inetpub\filters\SalesFilter.dll" />
      </isapiFilters>
   </system.webServer>
</configuration>

サンプル コード

次の例では、サーバー上で SalesQueryIsapi という名前の ISAPI フィルターを構成します。 各例では、name プロパティを使って ISAPI フィルターの名前を指定し、enableCache プロパティを使って HTTP.sys キャッシュを無効にし、path プロパティを使って ISAPI DLL の場所を指定しています。

AppCmd.exe

appcmd.exe set config -section:system.webServer/isapiFilters /+"[name='SalesQueryIsapi',path='c:\Inetpub\www.contoso.com\filters\SalesQueryIsapi.dll',enabled='True',enableCache='True']" /commit:apphost

Note

AppCmd.exe を使用してこれらの設定を構成する場合は、commit パラメーターを必ず apphost に設定する必要があります。 これにより、ApplicationHost.config ファイルの適切な location セクションに構成設定がコミットされます。

C#

using System;
using System.Text;
using Microsoft.Web.Administration;

internal static class Sample
{
   private static void Main()
   {
      using (ServerManager serverManager = new ServerManager())
      {
         Configuration config = serverManager.GetApplicationHostConfiguration();
         ConfigurationSection isapiFiltersSection = config.GetSection("system.webServer/isapiFilters");
         ConfigurationElementCollection isapiFiltersCollection = isapiFiltersSection.GetCollection();

         ConfigurationElement filterElement = isapiFiltersCollection.CreateElement("filter");
         filterElement["name"] = @"SalesQueryIsapi";
         filterElement["path"] = @"c:\Inetpub\www.contoso.com\filters\SalesQueryIsapi.dll";
         filterElement["enabled"] = true;
         filterElement["enableCache"] = true;
         isapiFiltersCollection.Add(filterElement);

         serverManager.CommitChanges();
      }
   }
}

VB.NET

Imports System
Imports System.Text
Imports Microsoft.Web.Administration

Module Sample
   Sub Main()
      Dim serverManager As ServerManager = New ServerManager
      Dim config As Configuration = serverManager.GetApplicationHostConfiguration
      Dim isapiFiltersSection As ConfigurationSection = config.GetSection("system.webServer/isapiFilters")
      Dim isapiFiltersCollection As ConfigurationElementCollection = isapiFiltersSection.GetCollection
      Dim filterElement As ConfigurationElement = isapiFiltersCollection.CreateElement("filter")
      filterElement("name") = "SalesQueryIsapi"
      filterElement("path") = "c:\Inetpub\www.contoso.com\filters\SalesQueryIsapi.dll"
      filterElement("enabled") = True
      filterElement("enableCache") = True
      isapiFiltersCollection.Add(filterElement)
      serverManager.CommitChanges()
   End Sub
End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var isapiFiltersSection = adminManager.GetAdminSection("system.webServer/isapiFilters", "MACHINE/WEBROOT/APPHOST");
var isapiFiltersCollection = isapiFiltersSection.Collection;

var filterElement = isapiFiltersCollection.CreateNewElement("filter");
filterElement.Properties.Item("name").Value = "SalesQueryIsapi";
filterElement.Properties.Item("path").Value = "c:\\Inetpub\\www.contoso.com\\filters\\SalesQueryIsapi.dll";
filterElement.Properties.Item("enabled").Value = true;
filterElement.Properties.Item("enableCache").Value = true;
isapiFiltersCollection.AddElement(filterElement);

adminManager.CommitChanges();

VBScript

Set adminManager = createObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set isapiFiltersSection = adminManager.GetAdminSection("system.webServer/isapiFilters", "MACHINE/WEBROOT/APPHOST")
Set isapiFiltersCollection = isapiFiltersSection.Collection

Set filterElement = isapiFiltersCollection.CreateNewElement("filter")
filterElement.Properties.Item("name").Value = "SalesQueryIsapi"
filterElement.Properties.Item("path").Value = "c:\\Inetpub\\www.contoso.com\\filters\\SalesQueryIsapi.dll"
filterElement.Properties.Item("enabled").Value = True
filterElement.Properties.Item("enableCache").Value = True
isapiFiltersCollection.AddElement filterElement

adminManager.CommitChanges()