動的な型: <dynamicTypes>

概要

<httpCompression> 要素の <dynamicTypes> 要素には、IIS 7 が動的に圧縮する型のリストに一意の MIME の種類を追加する <add> 要素のコレクションが含まれます。

Note

特定のファイル名拡張子を "動的コンテンツ" として定義していた IIS 6.0 の HcScriptFileExtensions メタベース プロパティとは異なり、IIS 7 では、<dynamicTypes> 要素を使って、IIS 7 が動的に圧縮する MIME の種類を指定し、<handlers> 要素内のマッピングを使って、静的または動的コンテンツを参照するファイル名拡張子を指定します。

互換性

バージョン メモ
IIS 10.0 <dynamicTypes> 要素は、IIS 10.0 では変更されませんでした。
IIS 8.5 <dynamicTypes> 要素は、IIS 8.5 では変更されませんでした。
IIS 8.0 <dynamicTypes> 要素は、IIS 8.0 では変更されませんでした。
IIS 7.5 <dynamicTypes> 要素は、IIS 7.5 では変更されませんでした。
IIS 7.0 <httpCompression> 要素の <dynamicTypes> 要素は IIS 7.0 で導入されました。
IIS 6.0 <dynamicTypes> 要素は、IIS 6.0 の HcScriptFileExtensions メタベース プロパティに多少似ています。

段取り

HTTP 圧縮は、通常、IIS 7 以降の既定のインストールで使用可能です。 ただし、既定でインストールされるのは静的圧縮のみです。 静的または動的圧縮をインストールするには、次の手順を使います。

Windows Server 2012 または Windows Server 2012 R2

  1. タスク バーで [サーバー マネージャー]をクリックします。
  2. [サーバー マネージャー] で、[管理] メニューをクリックし、[役割と機能の追加] をクリックします。
  3. 役割と機能の追加ウィザードで、[次へ] をクリックします。 インストールの種類を選択し、[次へ] をクリックします。 宛先サーバーを選択し、[次へ] をクリックします。
  4. [サーバーの役割] ページで、[Web サーバー (IIS)][Web サーバー] の順に展開し、[パフォーマンス] を展開して、[静的なコンテンツ圧縮] または [動的コンテンツ圧縮]、あるいはその両方を選択します。 次へ をクリックします。
    Screenshot of the Dynamic Content Compression option being selected and highlighted.
  5. [機能の選択] ページで、[次へ] をクリックします。
  6. [インストール オプションの確認] ページで、[インストール] をクリックします。
  7. [結果] ページで、 [閉じる]をクリックします。

Windows 8 または Windows 8.1

  1. [スタート] 画面で、ポインターを左下隅まで移動し、[スタート] ボタンを右クリックし、[コントロール パネル] をクリックします。
  2. [コントロール パネル][プログラムと機能] をクリックし、[Windows の機能の有効化または無効化] をクリックします。
  3. [インターネット インフォメーション サービス][World Wide Web サービス][パフォーマンス機能] の順に展開し、[動的なコンテンツ圧縮][静的なコンテンツ圧縮] のどちらか一方または両方を選択します。
    Screenshot of the Static Content Compression folder being highlighted and selected.
  4. OK をクリックします。
  5. 閉じるをクリックします。

Windows Server 2008 または Windows Server 2008 R2

  1. タスク バーで [スタート] をクリックし、[管理ツール] をポイントして、[サーバー マネージャー] をクリックします。
  2. [サーバー マネージャー] 階層ウィンドウで [役割] を展開し、[Web サーバー (IIS)] をクリックします。
  3. [Web サーバー (IIS)] ウィンドウで、[役割サービス] セクションまでスクロールし、[役割サービスの追加] をクリックします。
  4. 役割サービスの追加ウィザード[役割サービスの選択] ページで、動的なコンテンツ圧縮をインストールする場合は [動的なコンテンツ圧縮] を選択し、静的なコンテンツ圧縮をインストールする場合は [静的なコンテンツ圧縮] を選択し、[次へ] を選択します。
    Screenshot of the Select Role Services wizard showing the Dynamic Content Compression option being selected and highlighted.
  5. [インストール オプションの確認] ページで、[インストール] をクリックします。
  6. [結果] ページで、 [閉じる]をクリックします。

Windows Vista または Windows 7

  1. タスク バーで、[スタート][コントロール パネル] の順にクリックします。
  2. [コントロール パネル][プログラムと機能] をクリックし、[Windows の機能の有効化または無効化] をクリックします。
  3. [インターネット インフォメーション サービス][World Wide Web サービス][パフォーマンス機能] の順に展開します。
  4. 動的な圧縮をインストールする場合は [動的 HTTP 圧縮] を選択し、静的なコンテンツ圧縮をインストールする場合は [静的なコンテンツ圧縮] を選択します。
    Screenshot of the H T T P Compression Dynamic folder being selected and highlighted.
  5. OK をクリックします。

操作方法

IIS 7 で動的コンテンツ タイプを設定するためのユーザー インターフェイスはありません。 プログラムで動的コンテンツ タイプを設定する方法の例については、このドキュメントのコード サンプルのセクションを参照してください。

構成

属性

なし。

子要素

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

動的 MIME の種類のコレクションに MIME の種類を追加します。
remove 省略可能な要素です。

動的 MIME の種類のコレクションから MIME の種類への参照を削除します。
clear 省略可能な要素です。

動的 MIME の種類のコレクションから MIME の種類へのすべての参照を削除します。

構成サンプル

次の既定の <httpCompression> 要素は、IIS 7 の ApplicationHost.config ファイルで構成されます。 この構成セクションは、<clear> 要素を使用しない限り、既定の構成設定を継承します。

<httpCompression
      directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
   <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
   <dynamicTypes>
      <add mimeType="text/*" enabled="true" />
      <add mimeType="message/*" enabled="true" />
      <add mimeType="application/javascript" enabled="true" />
      <add mimeType="*/*" enabled="false" />
   </dynamicTypes>
   <staticTypes>
      <add mimeType="text/*" enabled="true" />
      <add mimeType="message/*" enabled="true" />
      <add mimeType="application/javascript" enabled="true" />
      <add mimeType="*/*" enabled="false" />
   </staticTypes>
</httpCompression>

サンプル コード

次のコード サンプルでは、Office 2003 ドキュメントの MIME の種類を動的圧縮の種類のリストに追加しています。

(> [!注]

Office 2007 のドキュメントでは組み込みの圧縮が使われるため、IIS で圧縮する必要はありません。)

AppCmd.exe

appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/msword',enabled='True']" /commit:apphost

appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/vnd.ms-powerpoint',enabled='True']" /commit:apphost

appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/vnd.ms-excel',enabled='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 httpCompressionSection = config.GetSection("system.webServer/httpCompression");
         ConfigurationElementCollection dynamicTypesCollection = httpCompressionSection.GetCollection("dynamicTypes");

         ConfigurationElement addElement = dynamicTypesCollection.CreateElement("add");
         addElement["mimeType"] = @"application/msword";
         addElement["enabled"] = true;
         dynamicTypesCollection.Add(addElement);

         ConfigurationElement addElement1 = dynamicTypesCollection.CreateElement("add");
         addElement1["mimeType"] = @"application/vnd.ms-powerpoint";
         addElement1["enabled"] = true;
         dynamicTypesCollection.Add(addElement1);

         ConfigurationElement addElement2 = dynamicTypesCollection.CreateElement("add");
         addElement2["mimeType"] = @"application/vnd.ms-excel";
         addElement2["enabled"] = true;
         dynamicTypesCollection.Add(addElement2);

         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 httpCompressionSection As ConfigurationSection = config.GetSection("system.webServer/httpCompression")
      Dim dynamicTypesCollection As ConfigurationElementCollection = httpCompressionSection.GetCollection("dynamicTypes")

      Dim addElement As ConfigurationElement = dynamicTypesCollection.CreateElement("add")
      addElement("mimeType") = "application/msword"
      addElement("enabled") = True
      dynamicTypesCollection.Add(addElement)

      Dim addElement1 As ConfigurationElement = dynamicTypesCollection.CreateElement("add")
      addElement1("mimeType") = "application/vnd.ms-powerpoint"
      addElement1("enabled") = True
      dynamicTypesCollection.Add(addElement1)

      Dim addElement2 As ConfigurationElement = dynamicTypesCollection.CreateElement("add")
      addElement2("mimeType") = "application/vnd.ms-excel"
      addElement2("enabled") = True
      dynamicTypesCollection.Add(addElement2)

      serverManager.CommitChanges()
   End Sub

End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var httpCompressionSection = adminManager.GetAdminSection("system.webServer/httpCompression", "MACHINE/WEBROOT/APPHOST");
var dynamicTypesCollection = httpCompressionSection.ChildElements.Item("dynamicTypes").Collection;

var addElement = dynamicTypesCollection.CreateNewElement("add");
addElement.Properties.Item("mimeType").Value = "application/msword";
addElement.Properties.Item("enabled").Value = true;
dynamicTypesCollection.AddElement(addElement);

var addElement1 = dynamicTypesCollection.CreateNewElement("add");
addElement1.Properties.Item("mimeType").Value = "application/vnd.ms-powerpoint";
addElement1.Properties.Item("enabled").Value = true;
dynamicTypesCollection.AddElement(addElement1);

var addElement2 = dynamicTypesCollection.CreateNewElement("add");
addElement2.Properties.Item("mimeType").Value = "application/vnd.ms-excel";
addElement2.Properties.Item("enabled").Value = true;
dynamicTypesCollection.AddElement(addElement2);

adminManager.CommitChanges();

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set httpCompressionSection = adminManager.GetAdminSection("system.webServer/httpCompression", "MACHINE/WEBROOT/APPHOST")
Set dynamicTypesCollection = httpCompressionSection.ChildElements.Item("dynamicTypes").Collection

Set addElement = dynamicTypesCollection.CreateNewElement("add")
addElement.Properties.Item("mimeType").Value = "application/msword"
addElement.Properties.Item("enabled").Value = True
dynamicTypesCollection.AddElement(addElement)

Set addElement1 = dynamicTypesCollection.CreateNewElement("add")
addElement1.Properties.Item("mimeType").Value = "application/vnd.ms-powerpoint"
addElement1.Properties.Item("enabled").Value = True
dynamicTypesCollection.AddElement(addElement1)

Set addElement2 = dynamicTypesCollection.CreateNewElement("add")
addElement2.Properties.Item("mimeType").Value = "application/vnd.ms-excel"
addElement2.Properties.Item("enabled").Value = True
dynamicTypesCollection.AddElement(addElement2)

adminManager.CommitChanges()