Fix for Could not download the Silverlight application error

by APIJunkie 8/2/2008 10:08:00 AM

If you receive the following error:  Could not download the Silverlight application. Check web server settings.

The problem might be the fact that the .xap mime type is not registered on the IIS server you are using.

If you have control over your server then you can just register the missing mime type.

If you are not that lucky you might need to find a workaround like the one below.

The idea is based on an older solution for Silverlight 1.0 and xaml files.

Since the problem is do to the fact that xap is not a registered mime type, we can cheat a little by creating an http handler that will handle requests for xap files.

The http handler will deliver the content of the xap file using a mime type that is known to the server. 

Since a xap file is actually a zip file we can use that mime type as the delivery content type.

Example:

Create a new class file called HttpXapHandler.cs.

Copy the following code to the file and add the file to your App_Code directory.

/// <summary>

/// HttpXapHandler class - handle requests to xap file through a back door nick named x-zip-compressed.

/// </summary>

public class HttpXapHandler : IHttpHandler

{

public void ProcessRequest(HttpContext context)

{

// get file name from request query string

string fileName = context.Request["fileName"];

// check if the file is valid -> its up to you to validate in a way that makes sense to you...

if (!validateFile(fileName))

{

context.Response.Write(
"<br>Bad file request<br>");

context.Response.End();

}

// set mime type to zip file because a xap file is actually a zip file

context.Response.ContentType = "application/x-zip-compressed";

context.Response.TransmitFile(context.Server.MapPath(fileName));

context.Response.End();

}

// naive test for valid xap file -> just test if the file requested is actualy a .xap file

public bool validateFile(string fileName)

{

fileName = fileName.ToUpper();

if ((fileName.Length > 4) &&(fileName.Substring(fileName.Length - 4).CompareTo(".XAP") == 0)

)

return true;

else

return false;

}

public bool IsReusable

{

get

{

return false;

}

}

}

// EOF HttpXapHandler

After you created the http handler add the following line to your web.config file inside the httpHandlers section(note the bold part):

<httpHandlers> <add verb="*" path="GetXapFile.ashx" type="HttpXapHandler" validate="false"/>

</httpHandlers>

Now that we have an http xap handler our web site should be able to accept requests like this:

http://www.MySiteNameGoesHere.com/getXapFile.ashx?fileName=Silverlight2.xap

To actually use this inside a web page take a look at the next example.

Usage example:

To access the .xap files in your web pages you will need to replace each occurrence of the source=[xap file name] with source=getXapFile.ashx?fileName=[xap file name].

In your html page this will look something like the following (note the bold part):

<div id="silverlightControlHost">

<object data="data:application/x-silverlight," type="application/x-silverlight-2-b2" width="100%" height="100%">

<param name="source" value="getXapFile.ashx?fileName=mySilverlight2file.xap"/>

<param name="onerror" value="onSilverlightError" />

<param name="background" value="white" />

 

<a href="http://go.microsoft.com/fwlink/?LinkID=115261" style="text-decoration: none;">

<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>

</a>

</object>

<iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>

</div>

good luck!

Currently rated 5.0 by 3 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

IIS | Silverlight | Troubleshoot

Rewrite URL and HttpHandler problems on IIS with certain character types

by APIJunkie 7/30/2008 12:01:00 AM

Trying to rewrite URL's or custom handle URL's on IIS 6/7 can lead to HTTP errors on the IIS level.

The problem is that some characters like a question mark (?) are considered illegal by IIS when they are a part of a URL file name or path.

Example:

http://www.mydomain.com/MyUrlWithQMark?.ashx

Will produce: HTTP Error 404 - File or directory not found, even if there is an HTTP handler defined for that file type.

Since those characters are not allowed by IIS, requests containing those characters are blocked on the Http.sys level before they ever reach the appropriate HttpHandler.

Unfortunately this means that ASP.Net code does not get a chance to handle URL's that contain characters dimmed illegal by IIS.

Currently the only solution is to change IIS registry settings that effect the way Http.sys handles those types of characters.

Specifically you will need to change the AllowRestrictedChars setting from 0 to 1.

The main problem with this solution is that if you don't have access to those registry settings you have a problem!

For example people using shared hosting solutions or shared servers where some sites want to allow this option and some don't will not be able to use this solution.

I hope this will change in future versions of IIS. in my opinion the AllowRestrictedChars option should be configurable per site through an ASP.NET configuration option.

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

IIS | .NET | Web Development

How to configure sourcesafe for internet access

by APIJunkie 5/2/2008 7:17:00 AM

I was looking for a good source on setting up sourcesafe access over HTTP/HTTPS.

Unfortunately MSDN help on this subject is a little scarce.

I found this great guide for setting up sourcesafe over an internet connection

It is a very detailed step by step guide that can get you up and running very fast.

Kudos to Alin Constantin for the great guide :)

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

IIS | How To | sourcesafe

Breaking changes in ASP.Net 2.0 HTTP Handlers when moving from IIS5 on Windows 2000 to IIS6 on Windows 2003

by APIJunkie 11/14/2007 11:27:00 PM

 If you use http handlers you might run into the same problem we had.

 On ASP 2.0, IIS 5, Windows 2000 the default http handlers are called automatically when they are not handled by your handler.

 On ASP 2.0, IIS 6, Windows 2003 the default http handlers do not get called and you receive a page error or missing content on your page depending on the content type.

 Example of problem:

 Let’s assume you have an HTTP handler that is configured in your web config file like this:

     <httpHandlers>

      <add verb="GET" path="ab*.jpg" type="WebLib.JPGHTTPHandler,WebLib"></add>

    </httpHandlers>

 The above handler will get called every time an “ab*.jpg” file will be requested.

That is to say a file that starts with “ab” and has the extension “.jpg”.

 On IIS 5 when a file that has a “.jpg” extension and does not start with “ab” is requested, it will be handled by a default ASP.NET handler.

 On IIS6 you will receive an error (in this case. jpg images will be missing from the requested page).

 One way to solve this is to explicitly tell ASP.NET to call the ASP.NET static file handler for every file that has the same extension but is not handled by our handler.

     <httpHandlers>

      <add verb="GET" path="ab*.jpg" type="WebLib.JPGHTTPHandler,WebLib"></add>

      <add verb="GET" path="*.jpg" type="System.Web.StaticFileHandler"></add>

    </httpHandlers>

 Note that the order of handlers in the above example is important. You should put the static file handler after your custom one! If you don’t, your handler will not get called, only the static file handler will get called for all .jpg files.

 You can find more information about the problem and possible solutions at: http://support.microsoft.com/Default.aspx?kbid=909641

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

IIS | .NET

Installing IIS on a 2003 server machine with SP2 and .Net 2.0 already installed

by APIJunkie 11/5/2007 6:20:00 PM


 Unlike the ordeal I had with installing IIS on the XP machine this was much easier.
 The major bug in XP pro that causes the installation to fail does not seem to exist in Windows 2003 SP2.
 
 I did have to reregister .NET (solution 2 on XP) and you will probably need to add authentication if you wish to debug on the server (solution 3 on XP).

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

IIS | .NET

Installing IIS on an XP machine with SP2 and .Net 2.0 already installed

by APIJunkie 11/5/2007 12:40:00 PM

I recently had to install IIS on an XP Pro machine with service pack 2 and .NET already installed.
 
All in all it was quite an annoying and time consuming ordeal for something that was supposed be a walk in the park.
 
Here is the list of the problems I encountered and the solutions I used:
 
1. Unless you are extremely lucky you will probably run into the infamous IIS installation bug.
 
I got the following error message while trying to install IIS:
 
“Setup cannot copy the file staxmem.dll...”
 
To solve this problem follow the instructions in the link below *:

http://support.microsoft.com/default.aspx?scid=kb;en-us;894351

 * Note that they offer 2 solutions and for me solution number 1 didn’t work so I had to go for solution number 2(merge XP setup and SP2 setup). I hope you will be luckier and avoid the need to download SP2 and merge it with the original XP installation files.
 
2. After installing IIS. Dot Net needs to be reregistered in order to work properly.
 
I got the following error after installing IIS and trying to run an ASP.NET web project:
 
“System.Web.Hosting.HostingEnvironmentException: Failed to access IIS metabase. The process account used to run ASP.NET must have read access to the IIS metabase (e.g. IIS://servername/W3SVC). For information on modifying metabase permissions, please see http://support.microsoft.com/?kbid=267904.”
 
I had to run the following command line to reregister .net 2.0 and make it work properly:
 
C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe –i
 
You can find more info about aspnet_regiis.exe here:
http://msdn2.microsoft.com/en-us/library/k6h9cz8h(VS.80).aspx

 3. After all that, debugging still did not work because my IIS default authentication options did not include integrated windows authentication.
 
I got the following error:
 
“Unable to start debugging on the web server. Debugging Failed Because Integrated Windows Authentication Is Not Enabled…”
 
To fix this go here:
http://msdn2.microsoft.com/en-us/library/x8a5axew(VS.80).aspx


I hope this will save some one else, some time, some day…
 
 

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

IIS | .NET

Powered by BlogEngine.NET 1.2.0.0
Theme by Mads Kristensen

About the author

Name of author

My name is Bacon…James Bacon.

I am an API wars veteran I was wounded by x86 assembly, recovered and moved on to C. I am currently stuck in C++ and sniffing .NET.

I am mainly here to ramble about coding, various API’s, Junkies(me especially) and everything else that happens between coders and their significant other.

E-mail me Send mail


Calendar

<<  November 2008  >>
MoTuWeThFrSaSu
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

View posts in large calendar

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Sign in