Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I setup an IIS MIME type in .NET?

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.

like image 326
Aaron Fischer Avatar asked Oct 24 '08 17:10

Aaron Fischer


People also ask

What is IIS MIME type?

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.

How do I add a MIME type?

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.

Which MIME type is default MIME type present in IIS?

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.

What is MIME type in asp net?

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.


2 Answers

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.

like image 126
Kev Avatar answered Sep 21 '22 18:09

Kev


'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?

like image 36
TomEberhard Avatar answered Sep 22 '22 18:09

TomEberhard