silverlight自定义升级路径

本文介绍了一种在客户端无法访问互联网的情况下部署Silverlight应用程序的方法。通过本地服务器提供Silverlight安装包及更新,确保应用程序正常运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

vs自动生成Silverlight加载页面,安装和升级都会自动连接到微软网站上下载更新。

但一些企业级应用中,客户端不能访问外网,就导致Silverlight技术应用有缺陷。

 

一般的解决方案是,将silverlight安装程序上传到服务器上,在Html中添加该地址,代码如下:

<form id="form1" runat="server" style="height:100%">
    <div id="silverlightControlHost">
        <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
		  <param name="source" value="ClientBin/Map.xap"/>
		  <param name="onError" value="onSilverlightError" />
		  <param name="background" value="white" />
		  <param name="minRuntimeVersion" value="4.0.50826.0" />
		  <param name="autoUpgrade" value="true" />
		  <a href="http://localhost/Silverlight.exe" style="text-decoration:none">
 			  <img src="http://localhost/SLMedallion_CHS.png" alt="获取 Microsoft Silverlight" style="border-style:none"/>
		  </a>
	    </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
    </form>


此方案对于没有安装过的客户端有效,但如果客户端已经安装过Silverlight,而开发的Silverlight版本较高,即minRuntimeVersion比客户端的版本高,则此时客户端仍会自动连接到微软网站去升级。

 

最好的解决方案应该是使用silverlight.js去加载Silverlight,代码如下: 

<script type="text/javascript" src="Silverlight.js"></script>
     <script type="text/javascript">
        window.onload = function() {
            silverlightControlHost.innerHTML = embedSilverlight(null, "sl", "");
        }

        function embedSilverlight(parentElement, pluginId, userContext) {
           var getSilverlightMethodCall = "http://localhost/Silverlight.exe"
        var installImageUrl = "http://localhost/SLMedallion_CHS.png";
        var imageAltText = "Get Microsoft Silverlight";
        var altHtml = 
            "<a href='{1}' style='text-decoration: none;'>" +
            "<img src='{2}' alt='{3}' " +
            "style='border-style: none'/></a>";
        altHtml = altHtml.replace('{1}', getSilverlightMethodCall);
        altHtml = altHtml.replace('{2}', installImageUrl);
        altHtml = altHtml.replace('{3}', imageAltText);

            return Silverlight.createObjectEx({
                        source: "ClientBin/Map.xap",
                        id: "sl", 
                        properties: {
                            width: "100%", 
                            height: "100%",
                            background: "white", 
                            alt: altHtml,
                            version: "5.0.61118.0",
			    autoUpgrade:false },
                        events: {
                            onError: onSLError, 
                            onLoad: onSLLoad },
			enableGPUAcceleration: false
                    });
        }

        function onSLLoad(plugIn, userContext, sender) {
            window.status +=
                plugIn.id + " loaded into " + userContext + ". ";
        }

        function onSLError(sender, args) {
            // Display error message.
alert(args);
        }
    </script>

<form id="form1" runat="server" style="height: 100%">
    <div id="silverlightControlHost"></div>
    <iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe>
    </form>

 

要注意的是autoUpgrade要设置为false.

 

解决这个问题搞了好久,希望对你有用。


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值