Can I setup a custom MIME type through ASP.NET or some .NET code? I need to register the Silverlight XAML and XAP MIME types in IIS 6.
MIME type in IIS MIME types in IIS are used to define and allow a specific file type to be served out by IIS. Usually this is used with new media files types, such as FLV, MP4, and etc.
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.
If IIS does not recognize the file name extension requested by the client, IIS sends the content as the default MIME type, which is Application. This MIME type signifies that the file contains application data, and it usually means that clients cannot process the file. Type a file name extension.
A media type, also called a MIME type, identifies the format of a piece of data. In HTTP, media types describe the format of the message body. A media type consists of two strings, a type and a subtype. For example − text/html.
To add to the master mime type list:
using (DirectoryEntry mimeMap = new DirectoryEntry("IIS://Localhost/MimeMap"))
{
PropertyValueCollection propValues = mimeMap.Properties["MimeMap"];
IISOle.MimeMapClass newMimeType = new IISOle.MimeMapClass();
newMimeType.Extension = extension; // string - .xap
newMimeType.MimeType = mimeType; // string - application/x-silverlight-app
propValues.Add(newMimeType);
mimeMap.CommitChanges();
}
Add a reference to :
'System.DirectoryServices' on the .NET add references tab
'Active DS IIS Namespace Provider' on the COM add references tab.
To configure a mime type for a specific site, change ..
'IIS://Localhost/MimeMap'
to
'IIS://Localhost/W3SVC/[iisnumber]/root'
...replacing '[iisnumber]'
with the IISNumber of the website.
'Active DS IIS Namespace Provider' on the COM add references tab.
If it's not there, you have to install IIS on your machine.
See Is there a way to get ALL the MIME types instead of wrinting a huge case statement?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With