This article suggests a workaround to host simple Silverlight applications with XAML files where they are blocked by ISP or MIME type is not yet updated in IIS.
After the Silverlight control is created, it contains a property called '
createSilverlight() is generated while referring to an XAML file on the server. When this code gets executed and Silverlight calls the server for the XAML file, if it is not returned or blocked by the web server a blank page appears (with no errors!).
One solution to get around the problem is to change the extension of XAML file to something else, like XML or TXT and change the source file name extension in
createSilverLight() method to match the same. This is a quick solution if your project is deployment ready and your project deadline was yesterday!
The code for the generic file handler is given below:
public class GetXAMLFile : IHttpHandler
string fileList = ",scene.xaml,";
public void ProcessRequest(HttpContext context)
string fname = context.Request["fname"].ToString().ToLower();
if (fileList.IndexOf("," + fname + ",") == -1)
context.Response.ContentType = "text/xaml";
string uri = context.Request.Url.AbsoluteUri;
string xamlstring = System.IO.File.ReadAllText(
public bool IsReusable
The line for checking the file requested before sending the contents is to avoid any rogue application to call this handler and get access to contents of files other than the required XAML files.
After creating the handler, change the source line in
createSilverlight() function to:
Now when the Silverlight control loads, it calls the ASHX handler which will send the contents of the XAML file to the client.
Similarly to the above case with IIS and ASP.NET combination, if you are working with any other web server and facing similar problems, write and host a script of some extension type which can interpret a query string and send the contents of the XAML file. Take care to make sure that the
Response content type is set to '
text/xaml' so that the client interprets it correctly.
- 28th November, 2007: Initial post