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

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

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

概要

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

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

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

互換性

  IIS 7.0 IIS 6.0
注意 <staticContent><mimeMap> は IIS 7.0 で新たに導入された要素です。 <mimeMap> 要素は、IIS 6.0 の MimeMap メタベース プロパティに代わるものです。

セットアップ

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

方法

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

  1. タスク バーで [スタート] ボタンをクリックし、[管理ツール] をポイントして [インターネット インフォメーション サービス (IIS) マネージャー] をクリックします。

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

  3. [ホーム] ウィンドウで [MIME の種類] をダブルクリックします。

    拡大

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

    拡大

  5. [MIME の種類の追加] ダイアログ ボックスで、ファイル名拡張子と MIME の種類を追加し、[OK] をクリックします。

    拡大

構成

属性

属性 説明
fileExtension 必須の string 属性。

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

既定の値の全一覧については、このトピックの後半の「既定の構成」を参照してください。
mimeType 必須の string 属性。

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

既定の値の全一覧については、このトピックの後半の「既定の構成」を参照してください。

子要素

なし。

構成サンプル

次の構成サンプルでは、MIDI System Exclusive (Sysex) メッセージ ファイルおよびギター タブ (TAB) ファイルのファイルの種類を IIS に追加し、クライアントでこれらのファイルの種類をダウンロードできるようにします。

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

   </system.webServer>
</configuration>

サンプル コード

次のコード サンプルでは、MIDI System Exclusive (Sysex) メッセージ ファイルおよびギター タブ (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()