Happy New Year 2012!!! Hope this year will bring happiness, success, and prosperiority.

In this tutorial, I will show how to making HTML 5 video work with IIS Express. Ok, first I created a simple MVC Application with “File – New - Project – ASP.NET MVC 3 Web Application” and left the defaults to create an Application.  I added a videos folder and added a H.264 encoded mp4 video (one of the supported HTML5 Video formats) inside the folder.

Then, I added the following line of code in the “Index.cshtml” file.

<video src="@Url.Content("~/Videos/video.mp4")" id="myVideo" controls ></video>



All I got was the above.  Basically a broken link.  I verified that the path is right and the video is indeed playable on Windows Media Player etc.,

The issue was that, since by default Visual Studio uses the ASP.NET Development Server and the ASP.NET Development Server doesn’t have the flexibility to configure MIME types,  It doesn’t understand the video format and hence could not play.  When I ran the application on IE9 and checked the Network Tab of the Developer Toolbar, all I got was what you see below



I switched the Project to use IIS Express using “ProjectName” – Right Click – Properties – Web Tab



Still had the same result.  Since IIS Express also doesn’t have the MIME Type to play video, configured by default, it couldn’t recognize the video and couldn’t play it.

The simple option is to configure it to use the “Actual IIS” (in the above screen, remove the check from “Use IISExpress”) which can play the video.

But, thankfully
this blog post has steps on how to configure MIME types for IIS Express.  Only thing is, I had to change it for configuring the MIME type for playing MP4 video.

So, the steps are

1. Click on Start button
2. Type CMD
3. Right click on the CMD that is listed and choose “Run as Administrator”
4. Do a cd to navigate to the IIS Express directory CD “Program Files (x86)”\”IIS Express”
5. And then run the following command

appcmd set config /section:staticContent /+[fileExtension='.mp4',mimeType='vieo/mp4']

That’s it.  When I re-ran the application, it could play the video.



Please note, I was unable to configure or figure out how to do it for the ASP.NET Development Server.  So, if we need to play HTML5 Video from Visual Studio we either need to use IIS Express or use the full fledged IIS.  And from the performance and configuration perspective IIS Express offers a lot more than ASP.NET Development Server and hence it makes more sense to use IIS Express for local development.