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.0 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.0 configuration settings.
| |
IIS 7.0 |
IIS 6.0 |
| Notes |
The <mimeMap> element of the <staticContent> element is new in IIS 7.0. |
The <mimeMap> element replaces the IIS 6.0 MimeMap metabase property. |
The <mimeMap> element of the <staticContent> element is included in the default installation of IIS 7.0.
How to add a MIME type to a Web site or application
- On the taskbar, click Start, point to Administrative Tools, and then click Internet Information Services (IIS) Manager.
- In the Connections pane, go to the site, application, or directory for which you want to add a MIME type.
- In the Home pane, double-click MIME Types.
- In the MIME Types pane, click Add... in the Actions pane.
- In the Add MIME Type dialog box, add the file name extension and MIME type, and then click OK.
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>
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()