如何强制重新下载Silverlight XAP文件

7 versioning silverlight browser-cache xap

我试图找出如何强制浏览器重新下载.xap文件,如果新版本可用,但旧版本仍然在浏览器中缓存.

我见过另一个帖子: 你如何强制Firefox不缓存或重新下载Silverlight XAP文件?

最好的解决方案似乎是:

protected void Page_Load(object sender, EventArgs e)
{
    var versionNumber = Assembly.GetExecutingAssembly().GetName().Version.ToString();
    this.myApp.Source += "?" + versionNumber;
}
Run Code Online (Sandbox Code Playgroud)

但是,我没有得到this.myApp部分.那是什么样的对象?我很抱歉重新开放,但我希望人们能够发布完整的解决方案.

谢谢

Ant*_*nes 8

您所看到的是基于asp:SilverlightWeb服务器控件的代码,但该控件已从Silverlight 3开始停止.

现在我们要么直接使用object标签,要么敲掉我们自己的服务器控件来呈现我们对object标签的偏好.

作为对象标签,它看起来像这样: -

<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 id="xapSource" runat="server" name="source" value="ClientBin/SilverlightApplication1.xap"/>
      <param name="onError" value="onSilverlightError" />
      <param name="background" value="white" />
      <param name="minRuntimeVersion" value="4.0.50303.0" />
      <param name="autoUpgrade" value="true" />
      <param name="initParams" id="initParams" runat="server" />
      <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50303.0" style="text-decoration:none">
          <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
      </a>
    </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
</form>
Run Code Online (Sandbox Code Playgroud)

注意源参数上的id和runat ="server".有了它,页面加载可能看起来像这样: -

protected void Page_Load(object sender, EventArgs e)
{
    string xapPhysicalPath = Server.MapPath(xapSource.Attributes["value"]);
    DateTime lastWrite = System.IO.File.GetLastWriteTime(xapPhysicalPath);
    xapSource.Attributes["value"] = xapSource.Attributes["value"] + "?" + lastWrite.ToString("yyyyMMddThh:mm:ss");

}
Run Code Online (Sandbox Code Playgroud)

这将确保当xap发生变化时,用于源的url总是会改变.您遇到的原始代码存在缺陷,因为xap仍然可以在没有完全未连接的程序集版本号更改的情况下进行更改.