Wednesday, July 9, 2008

Make your ASP.NET web site to serve .MCML pages

When you are working in Windows Media Center Web Hosted application projects you are going to have the need to generate dynamic MCML pages to serve your MCE client applications. MCE web hosted applications retrieve all the MCML pages and the data from the server, rendering all the markup code before displaying it to the user. When you need to serve dynamic generated data, you need to dynamicaly create .mcml pages in the server with the data and make the web site serve those pages to the client.

The problem is that an ASP.NET web server does not serve MCML (.mcml) pages by default. In order to deliver the .mcml pages to the client you need to make the ASP.NET web server to serve the .mcml pages as XML pages (.mcml pages are xml based markup code). The cool thing is that you can extend this approach to make the web server to serve any kind of files you want. For example, for a project we worked on we also needed to serve our custom dynamic data xml pages (.dax) which are xml pages containing dynamicly generated xml data.

To make the ASP.NET web site to serve this new file types, you have to include those file extensions in the web site MIME types.

To add new MIME types on IIS 7 (Vista Machine) follow this steps:

1. Click on the start button, type IIS in the search box. The first result should be the Internet Information Services (IIS) Manager, open it, and the IIS 7 Manager console will appear. Note: if it doesn’t you might need to install the IIS windows features from the control panel (I’ll post how to do it separately).

2. Expand the server tree to web sites and click on your web site from the tree view of the websites, and its options will appear in the center of the window. From the Home options select MIME Types.

3. In the actions pane right click on add.

4. In the File Name Extension field type the name of the file extension (i.e.: “.mcml”) and in the MIME Type field type “text/xml”. This will make the web server to serve the new types as if they were xml files.

1. First, to enable Framework Extensions, go to IIS Manager, you can find it in the Start menu, under the Administrative Tools menu, and open it. The IIS 6 manager console will appear. Note: if it doesn’t you might need to install the IIS windows features from the control panel(I’ll post how to do it separately).

2. Browse in the tree view to find the Web Service Extensions.

3. Select .Net Framework 2.0 Extensions and allow those.

4. Now, you need to add the new MIME types to your web site. Expand the contents of your website in the IIS Manager. Find the web folder from where the pages will be served, right click it and go to options.

5. In the Directory tab under Application Settings press the create button that will enable all the files inside to serve as application files, and change the Execute permissions drop down to Scripts Only.

6. After that the configuration button will enable, click it and the application configuration window will appear.

7. Add a new application extension for .mcml using the following values.
• In executable use the following address: \%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll
• For Extension: .mcml
• Verbs - use limit to: GET,HEAD,POST,DEBUG
• Script Engine: Checked
• Verify that file exists: Unchecked

8. Press ok to create the Extension then OK again to exit the Application Settings, and finally OK to the UI properties.

9. Add a new application extension for .dax using the following values:
• In executable use the following address: \%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll
• For Extension: .dax
• Verbs - use limit to: GET,HEAD,POST,DEBUG
• Script Engine: Checked
• Verify that file exists: Unchecked

10. Press ok to create the Extension then OK again to exit the Application Settings, and finally OK to the UI properties.

11. Open the web.config file of your web site and make sure you specify the handlers for the new MIME types. The “httpHandlers” should be included in the section of the web.config file. Here is an example of the handler for .mcml files: .