Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting MIME types using the ASP.NET Development Server

I added the following to the web.config file, but this seems to be ignored by the development server thats built into Visual Studio 2010. Does anyone know how to alter the MIME types in the development server?

<system.webServer>     <validation validateIntegratedModeConfiguration="false"/>     <modules runAllManagedModulesForAllRequests="true"/>     <staticContent>         <mimeMap fileExtension=".mp4" mimeType="video/mp4" />                   <mimeMap fileExtension=".ogg" mimeType="audio/ogg" />                   <mimeMap fileExtension=".oga" mimeType="audio/ogg" />                   <mimeMap fileExtension=".ogv" mimeType="video/ogg" />                   <mimeMap fileExtension=".webm" mimeType="video/webm" />          </staticContent>   </system.webServer> 
like image 661
Martin Beeby Avatar asked May 07 '11 23:05

Martin Beeby


People also ask

How do I set up 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.

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.

What is a MIME type and how does a Web server make use of it?

MIME types describe the media type of content, either in email, or served by web servers or web applications. They are intended to help provide a hint as to how the content should be processed and displayed. Examples of MIME types: text/html for HTML documents.

What is 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.


2 Answers

The built-in development web server in Visual Studio (Cassini) has no knowledge of <system.webServer>, only IIS7.x or IIS7.5 Express will consume these settings.

Also the static file content types in Visual Studio's development web server are hard coded.

From Microsoft.VisualStudio.WebHost.Connection (disassembled using .NET Reflector):

private static string MakeContentTypeHeader(string fileName) {     string str = null;     FileInfo info = new FileInfo(fileName);     switch (info.Extension.ToLowerInvariant())     {         case ".bmp":             str = "image/bmp";             break;          case ".css":             str = "text/css";             break;          case ".gif":             str = "image/gif";             break;          case ".ico":             str = "image/x-icon";             break;          case ".htm":         case ".html":             str = "text/html";             break;          case ".jpe":         case ".jpeg":         case ".jpg":             str = "image/jpeg";             break;          case ".js":             str = "application/x-javascript";             break;     }     if (str == null)     {         return null;     }     return ("Content-Type: " + str + "\r\n"); } 

To be honest, with the advent of IIS7.5 Express I can't see why you'd want to use the built-in web server. Cassini can be the cause of so much confusion when it comes to deployment time on a production server because it's nothing like the real deal (security, configuration etc) whereas if you can get your site running on IIS7.5 Express then there's a fairly high probability that deployment onto a production IIS7.5 server will "just work".

I wouldn't be surprised if Microsoft yanked the Cassini server from the next version of Visual Studio given how easy it is to run with IIS7.5 Express.

like image 58
Kev Avatar answered Sep 30 '22 01:09

Kev


Just had this issue but had to find the config for IIS Express so I could add the mime types. For me, it was located at C:\Users\<username>\Documents\IISExpress\config\applicationhost.config and I was able to add in the correct "mime map" there.

like image 23
longda Avatar answered Sep 30 '22 02:09

longda