静的コンテンツ MIME マッピングの追加 <mimeMap>

概要

<staticContent> 要素の <mimeMap> 要素は、静的コンテンツ タイプのコレクションに一意の MIME タイプを追加します。 各 <mimeMap> エントリは、次の 2 つの部分で構成されている必要があります。

  • fileExtension 属性で指定される一意のファイル名拡張子 (例: ".txt"、".png" など)。
  • mimeType 属性で指定されるファイル名拡張子の MIME の種類 (例: "text/plain"、"image/jpg" など)。

Note

IIS 7 では、<staticContent> 要素に追加されていないファイルの種類や、既定で <handlers> 要素にマッピングがあるファイルの種類は返されません。 この動作により、IIS 7 構成設定にマッピングがないファイルへの不正アクセスが防止されます。

互換性

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

段取り

<staticContent> 要素の <mimeMap> 要素は、IIS 7 の既定のインストールに含まれています。

操作方法

MIME の種類を Web サイトまたはアプリケーションに追加する方法

  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. [接続] ウィンドウで、MIME の種類を追加するサイト、アプリケーション、またはディレクトリに移動します。

  3. [ホーム] ウィンドウで、[MIME の種類] をダブルクリックします。
    Screenshot that shows the Default Web Site Home pane. MIME Types is selected.

  4. [MIME の種類] ウィンドウで、[操作] ウィンドウの [追加] を選択します。
    Screenshot that shows the MIME Types pane.

  5. [Add MIME Type]\(MIME の種類の追加\) ダイアログ ボックスで、ファイル名拡張子と MIME の種類を追加し、[OK] を選択します。
    Screenshot that shows the Add MIME Type dialog box. Tab is entered in the File name extension box. Text slash plain is entered in the MIME type text box.

構成

属性

属性 説明
fileExtension 必須の文字列属性です。

MIME の種類の一意のファイル名拡張子を指定します。

既定値の完全な一覧については、このトピックの後の「既定の構成」セクションを参照してください
mimeType 必須の文字列属性です。

ファイルの種類と、この種類のファイル名拡張子を使用するアプリケーションを指定します。

既定値の完全な一覧については、このトピックで後述する「既定の構成」セクションを参照してください。

子要素

なし。

構成サンプル

次の構成サンプルでは、MIDI システム排他 (Sysex) メッセージと Guitar Tablature (TAB) ファイルのファイルの種類を IIS に追加して、クライアントがこれらのファイルの種類をダウンロードできるようにします。

<configuration>
   <system.webServer>
      <staticContent>
         <mimeMap fileExtension=".syx" mimeType="application/octet-stream" />
         <mimeMap fileExtension=".tab" mimeType="text/plain" />
      </staticContent>
   </system.webServer>
</configuration>

サンプル コード

次のコード サンプルでは、MIDI システム排他 (Sysex) メッセージと Guitar Tablature (TAB) ファイルのファイルの種類を IIS に追加して、クライアントがこれらのファイルの種類をダウンロードできるようにします。

AppCmd.exe

appcmd.exe set config "Default Web Site" -section:system.webServer/staticContent /+"[fileExtension='syx',mimeType='application/octet-stream']"

appcmd.exe set config "Default Web Site" -section:system.webServer/staticContent /+"[fileExtension='tab',mimeType='text/plain']"

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.GetWebConfiguration("Default Web Site");
         ConfigurationSection staticContentSection = config.GetSection("system.webServer/staticContent");
         ConfigurationElementCollection staticContentCollection = staticContentSection.GetCollection();

         ConfigurationElement mimeMapElement = staticContentCollection.CreateElement("mimeMap");
         mimeMapElement["fileExtension"] = @"syx";
         mimeMapElement["mimeType"] = @"application/octet-stream";
         staticContentCollection.Add(mimeMapElement);

         ConfigurationElement mimeMapElement1 = staticContentCollection.CreateElement("mimeMap");
         mimeMapElement1["fileExtension"] = @"tab";
         mimeMapElement1["mimeType"] = @"text/plain";
         staticContentCollection.Add(mimeMapElement1);

         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.GetWebConfiguration("Default Web Site")
      Dim staticContentSection As ConfigurationSection = config.GetSection("system.webServer/staticContent")
      Dim staticContentCollection As ConfigurationElementCollection = staticContentSection.GetCollection

      Dim mimeMapElement As ConfigurationElement = staticContentCollection.CreateElement("mimeMap")
      mimeMapElement("fileExtension") = "syx"
      mimeMapElement("mimeType") = "application/octet-stream"
      staticContentCollection.Add(mimeMapElement)

      Dim mimeMapElement1 As ConfigurationElement = staticContentCollection.CreateElement("mimeMap")
      mimeMapElement1("fileExtension") = "tab"
      mimeMapElement1("mimeType") = "text/plain"
      staticContentCollection.Add(mimeMapElement1)

      serverManager.CommitChanges()
   End Sub

End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Default Web Site";
var staticContentSection = adminManager.GetAdminSection("system.webServer/staticContent", "MACHINE/WEBROOT/APPHOST/Default Web Site");
var staticContentCollection = staticContentSection.Collection;

var mimeMapElement = staticContentCollection.CreateNewElement("mimeMap");
mimeMapElement.Properties.Item("fileExtension").Value = "syx";
mimeMapElement.Properties.Item("mimeType").Value = "application/octet-stream";
staticContentCollection.AddElement(mimeMapElement);

var mimeMapElement1 = staticContentCollection.CreateNewElement("mimeMap");
mimeMapElement1.Properties.Item("fileExtension").Value = "tab";
mimeMapElement1.Properties.Item("mimeType").Value = "text/plain";
staticContentCollection.AddElement(mimeMapElement1);

adminManager.CommitChanges();

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Default Web Site"
Set staticContentSection = adminManager.GetAdminSection("system.webServer/staticContent", "MACHINE/WEBROOT/APPHOST/Default Web Site")
Set staticContentCollection = staticContentSection.Collection

Set mimeMapElement = staticContentCollection.CreateNewElement("mimeMap")
mimeMapElement.Properties.Item("fileExtension").Value = "syx"
mimeMapElement.Properties.Item("mimeType").Value = "application/octet-stream"
staticContentCollection.AddElement(mimeMapElement)

Set mimeMapElement1 = staticContentCollection.CreateNewElement("mimeMap")
mimeMapElement1.Properties.Item("fileExtension").Value = "tab"
mimeMapElement1.Properties.Item("mimeType").Value = "text/plain"
staticContentCollection.AddElement(mimeMapElement1)

adminManager.CommitChanges()