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

发布于 2024-11-07 04:53:20 字数 582 浏览 4 评论 0原文

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

我看过另一个线程: 如何强制 Firefox 不缓存或重新下载 Silverlight XAP 文件?

最好的解决方案似乎是:

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

但是,我没有得到 this.myApp 部分。那是什么样的物体?我很抱歉重新打开此问题,但我希望人们能够发布完整的解决方案。

谢谢

I'm trying to figure out how to force the browser to re-download a .xap file if the new version is available and yet the old one is still cached in the browser.

I've seen the other thread:
How do you force Firefox to not cache or re-download a Silverlight XAP file?

The best solution seems to be:

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

However, I don't get the this.myApp part. What kind of object is that? I'm sorry for re-opening this, but I wish people would post complete solutions.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

灰色世界里的红玫瑰 2024-11-14 04:53:20

您看到的是基于 asp:Silverlight Web 服务器控件的代码,但该控件从 Silverlight 3 开始已停止使用。

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

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

<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>

注意源参数上的 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");

}

这将确保当 xap 更改时,用于源的 url 始终会更改。您遇到的原始代码存在缺陷,因为 xap 仍然可以更改,而无需更改完全未连接的程序集版本号。

What your looking at is code based on the asp:Silverlight web server control but that control was discontinued from Silverlight 3 onwards.

Now we either use the object tag directly or knock up our own server controls to render our preference of object tag.

As an object tag it would look something like this:-

<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>

Note the id and runat="server" on the source param. With that in place the page load could look something like this:-

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");

}

This would ensure the url used for the source would always change when the xap has changed. The original code you've come across is flawed in that it is still possible for the xap to change without the entirely unconnected assembly version number changing.

甜嗑 2024-11-14 04:53:20

您只需将当前日期时间附加到 xap 中,每次都会将其视为新的,因此客户端上不会进行缓存。

value="ClientBin/SilverlightApplication1.xap?<%=DateTime.Now%>"

希望这有帮助。

You can just append the current datetime to the xap and it will be seen as new each time, so no caching on the client.

value="ClientBin/SilverlightApplication1.xap?<%=DateTime.Now%>"

Hope this helps.

泡沫很甜 2024-11-14 04:53:20

myApp 可能是一个在页面中呈现 Silverlight 对象的 Web 控件。

通过设置其 Source 属性,指向 XAP 的 url 获取一个与以前版本不同的参数,导致浏览器使缓存的 xap 无效(为此参数设置了另一个值)。

The myApp is probably a web control that renders the Silverlight object in the page.

By setting its Source property the url that points to the XAP gets a parameter that is different from the previous version causing the browser to invalidate the cached xap(that had another value set for this parameter).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文