强制更新客户端Silverlight XAP 文件

时间:2022-09-25 15:51:11

在发布小程序更新的时候访问的总是原来的程序,猜想应该是缓存的原因。在网上查找方法

<div id="silverlightControlHost">
        <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
          <param name="source" value="ClientBin/ElecDemoSl.xap?<%=Guid.NewGuid().ToString() %>"/>
          <param name="onError" value="onSilverlightError" />
          <param name="background" value="white" />
          <param name="minRuntimeVersion" value="5.0.61118.0" />
          <param name="autoUpgrade" value="true" />
          <param name="enableGPUAcceleration" value="true" />
          <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=5.0.61118.0" style="text-decoration:none">
               <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="获取 Microsoft Silverlight" style="border-style:none"/>
          </a>
        </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>

在<param name="source" value="ClientBin/ElecDemoSl.xap?<%=Guid.NewGuid().ToString() %>"/>这行中添加绿色的代码就可以了。

以下方法通过网上查找

另一个解决方案,我更喜欢甚至包括检查XAP创建日期,并附加参数name =“Source”来源

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

<%
    string strSourceFile = @"ClientBin/SilverlightApplication2.xap";
    string param;
    if (System.Diagnostics.Debugger.IsAttached)
        param = "<param name=\"source\" value=\"" + strSourceFile + "\" />";
    else
    {
        string xappath = HttpContext.Current.Server.MapPath(@"") + @"\" + strSourceFile;
        DateTime xapCreationDate = System.IO.File.GetLastWriteTime(xappath);
        param = "<param name=\"source\" value=\"" + strSourceFile + "?ignore="
                + xapCreationDate.ToString() + "\" />";
    }
    Response.Write(param);
%>
<param name="onError" value="onSilverlightError" />

 

参考文章

http://www.codeproject.com/Articles/143414/Prevent-your-Silverlight-XAP-File-from-Caching-in

http://kevinfan.blog.51cto.com/1037293/933181/