Adding Static Content MIME Mappings <mimeMap>

Overview

The <mimeMap> element of the <staticContent> element adds a unique MIME type to the collection of static content types. Each <mimeMap> entry must consist of two parts:

  • A unique file name extension that is specified by the fileExtension attribute, for example, ".txt", ".png", etc.
  • A MIME type for the file name extension that is specified by the mimeType attribute, for example, "text/plain", "image/jpg", etc.

Note: IIS 7 will not return file types that are not added to the <staticContent> element or that have mappings in the <handlers> element by default. This behavior prevents unauthorized access to files that do not have mappings in the IIS 7 configuration settings.

Compatibility

Version Notes
IIS 8.5 The <mimeMap> element was not modified in IIS 8.5.
IIS 8.0 The <mimeMap> element was not modified in IIS 8.0.
IIS 7.5 The <mimeMap> element was not modified in IIS 7.5.
IIS 7.0 The <mimeMap> element of the <staticContent> element was introduced in IIS 7.0.
IIS 6.0 The <mimeMap> element replaces the IIS 6.0 MimeMap metabase property.

Setup

The <mimeMap> element of the <staticContent> element is included in the default installation of IIS 7.

How To

How to add a MIME type to a Web site or application

  1. Open Internet Information Services (IIS) Manager:
    • If you are using Windows Server 2012 or Windows Server 2012 R2:
      • On the taskbar, click Server Manager, click Tools, and then click Internet Information Services (IIS) Manager.
    • If you are using Windows 8 or Windows 8.1:
      • Hold down the Windows key, press the letter X, and then click Control Panel.
      • Click Administrative Tools, and then double-click Internet Information Services (IIS) Manager.
    • If you are using Windows Server 2008 or Windows Server 2008 R2:
      • On the taskbar, click Start, point to Administrative Tools, and then click Internet Information Services (IIS) Manager.
    • If you are using Windows Vista or Windows 7:
      • On the taskbar, click Start, and then click Control Panel.
      • Double-click Administrative Tools, and then double-click Internet Information Services (IIS) Manager.
  2. In the Connections pane, go to the site, application, or directory for which you want to add a MIME type.
  3. In the Home pane, double-click MIME Types.

  4. In the MIME Types pane, click Add... in the Actions pane.

  5. In the Add MIME Type dialog box, add the file name extension and MIME type, and then click OK.

Configuration

Attributes

Attribute Description
fileExtension Required string attribute.

Specifies a unique file name extension for a MIME type.

See the Default Configuration section later in this topic for the complete list of default values
mimeType Required string attribute.

Specifies the type of file and the application that uses this kind of file name extension.

See the Default Configuration section later in this topic for the complete list of default values.

Child Elements

None.

Configuration Sample

The following configuration sample adds the file types for MIDI System Exclusive (Sysex) Messages and Guitar Tablature (TAB) files to IIS, thereby enabling clients to download these file types.

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

Sample Code

The following code samples add the file types for MIDI System Exclusive (Sysex) Messages and Guitar Tablature (TAB) files to IIS, thereby enabling clients to download these file types.

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