動的な種類 <dynamicTypes>

  • 概要
  • 互換性
  • セットアップ
  • 方法
  • 構成
  • サンプル コード

※本ページに挿入されている画像をクリックすると、画像全体が別ウィンドウで表示されます。

概要

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

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

互換性

  IIS 7.0 IIS 6.0
注意 <httpCompression><dynamicTypes> は IIS 7.0 で新たに導入された要素です。 <dynamicTypes> 要素は、IIS 6.0 の HcScriptFileExtensions メタベース プロパティと似ています。

セットアップ

HTTP 圧縮は、通常、IIS 7.0 の既定のインストールに含まれていますが、静的圧縮だけが既定でインストールされます。静的圧縮または動的圧縮をインストールするには、次の手順を実行します。

Windows Server 2008

  1. タスク バーで [スタート] ボタンをクリックし、[管理ツール] をポイントして [サーバー マネージャー] をクリックします。

  2. [サーバー マネージャー] ウィンドウのツリー表示で、[役割] を展開して [Web サーバー (IIS)] をクリックします。

  3. [Web サーバー (IIS)] ウィンドウで、[役割サービス] セクションまでスクロールして [役割サービスの追加] をクリックします。

  4. 役割サービスの追加ウィザードの [役割サービスの選択] ページで、動的圧縮をインストールする場合は [動的なコンテンツの圧縮] を、静的圧縮をインストールする場合は [静的なコンテンツの圧縮] を選択して、[次へ] をクリックします。

    拡大

  5. [インストール オプションの確認] ページで [インストール] をクリックします。

  6. [結果] ページで [閉じる] をクリックします。

Windows Vista

  1. タスク バーで [スタート] ボタンをクリックし、[コントロール パネル] をクリックします。

  2. コントロール パネルで、[プログラムと機能][Windows の機能の有効化または無効化] の順にクリックします。

  3. [Internet Information Services][World Wide Web サービス][性能機能] の順に展開します。

  4. 動的圧縮をインストールする場合は [HTTP 動的圧縮] を、静的圧縮をインストールする場合は [静的なコンテンツの圧縮] を選択します。

    拡大

  5. [OK] をクリックします。

方法

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

構成

属性

なし。

子要素

要素 説明
add オプションの要素。

動的な MIME の種類のコレクションに MIME の種類を追加します。
remove オプションの要素。

動的な MIME の種類のコレクションから 1 つの MIME の種類への参照を削除します。
clear オプションの要素。

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

構成サンプル

IIS 7.0 の ApplicationHost.config ファイルでは、次の既定の <httpCompression> 要素が構成されています。この構成セクションでは、<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

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()