Configuring a Web Server to Host Silverlight Content
Deploying Silverlight content to a production web server is a pretty easy process. Despite occasional misconception, Silverlight doesn't require a Microsoft-based web server: Apache can host up Silverlight content just as happily as IIS.
But there's one little gotcha: web servers are typically configured to only serve up a limited set of known file extensions as static content. That's all well and good, but Silverlight introduces two new file extensions (.xaml for loose XAML files and .xap for the zip-based binary packaging format). As a result, you need to add the MIME types for those file extensions to your web server so that it recognizes Silverlight content appropriately. Here are the MIME types you need to add to the server configuration:
Extension | MIME Type |
.xaml | application/xaml+xml |
.xap | application/x-silverlight-app |
That's all you have to do. Unfortunately, it's not possible to provide generic instructions for how to add MIME types, as it varies from server to server, but here are some links for various common web servers:
While you're updating the list of MIME types served, you might want to also add the relevant types to your web server to support WPF and ClickOnce applications. Here are the additional items you'll need:
Extension | MIME Type |
.manifest | application/manifest |
.application | application/x-ms-application |
.xbap | application/x-ms-xbap |
.deploy | application/octet-stream |
.xps | application/vnd.ms-xpsdocument |
But what if you're hosting your Silverlight application on a shared hosting service and your hoster doesn't give you access to change these settings? The good news is that there are two options available to you. Obviously, you could take advantage of Silverlight Streaming, our free hosting service for up to 10GB of Silverlight content.
Alternatively, you can "cheat" the web server by renaming the XAP file extension to a compatible MIME type. The XAP container is ZIP-based, so you can simply rename the output file from .xap to .zip and change the source param within the object tag contained in the HTML file to point to the new file location. Click on this hyperlink to see the technique in action - it's a plain HTML file that points to a ZIP file (containing the Silverlight content).
One last piece of good news: IIS 7, included in Windows Server 2008, already includes all the relevant MIME types for both WPF and Silverlight, including both .xap and .xaml extensions, so if you're using Windows Server 2008, you're all set. (The same applies to a clean install of Windows Vista SP1, although if you upgrade from the RTM to the SP1 release, your settings will remain unchanged until you uninstall and reinstall the IIS feature).
Comments
Anonymous
March 18, 2008
Following on very nicely from my last post on deploying Silverlight content to your own production serverAnonymous
March 18, 2008
Useful information once one gets a go-live license. Silverlight is looking like the solution for several projects we are potentially looking at now.Anonymous
March 18, 2008
Following on very nicely from my last post on deploying Silverlight content to your own production serverAnonymous
March 18, 2008
You've been kicked (a good thing) - Trackback from DotNetKicks.comAnonymous
March 19, 2008
The Silverlight.net website has 2 important Posts by Tim Sneath on Configuring a Web Server to Host SilverlightAnonymous
March 19, 2008
The comment has been removedAnonymous
March 21, 2008
John Stockton with a SL2 UserControl example and Tim Sneath on Web Server Configuration for SL2 contentAnonymous
April 02, 2008
Many thanks. Could not figure out why my xaml files did not seem to exist on the production server.Anonymous
May 06, 2008
The comment has been removedAnonymous
May 22, 2008
要部屬 Silverlight 元件到 Web Server 上是一件很簡單的事情,雖然 Silverlight 是微軟的技術,但不表示非微軟的 Web Server 就不能夠使用 Silverlight。SilverlightAnonymous
May 26, 2008
Hi.. Thsi is a gentle reminder..for the above query... Please do give in your inputs...That would be of great help.. Thanks and Regards, NirupamaAnonymous
June 17, 2008
I went to throw a small Silverlight sample application up on a web site to show to a client yesterday