Could not download the Silverlight application

Could not download the Silverlight application,第1张

概述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 serve

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!

总结

以上是内存溢出为你收集整理的Could not download the Silverlight application全部内容,希望文章能够帮你解决Could not download the Silverlight application所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1075989.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存