zoukankan      html  css  js  c++  java
  • Could not download the Silverlight application

    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;0;border:0px'></ iframe >

    </ div >

    good luck!

    作者:Angelo Lee
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
  • 相关阅读:
    JS——正则案例
    JS——正则
    JS——旋转木马
    JS——缓动框架的问题
    JS——缓慢动画封装案例
    JS——缓慢动画封装
    JS——隐式全局变量
    JS——样式获取的兼容写法
    JS——冒泡案例
    JS——事件冒泡与捕获
  • 原文地址:https://www.cnblogs.com/yefengmeander/p/2887779.html
Copyright © 2011-2022 走看看