问题描述
我正在尝试弄清楚如果新版本可用而旧版本仍缓存在浏览器中,如何强制浏览器重新下载 .xap 文件.
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.
我看过另一个帖子:如何强制 Firefox 不缓存或重新下载 Silverlight XAP 文件?
最好的解决方案似乎是:
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;
}
但是,我没有得到 this.myApp 部分.那是什么样的物体?我很抱歉重新打开这个,但我希望人们能发布完整的解决方案.
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.
谢谢
推荐答案
您所看到的是基于 asp:Silverlight
Web 服务器控件的代码,但该控件从 Silverlight 3 起已停止使用.
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>
注意源参数上的 id 和 runat="server".有了它,页面加载可能看起来像这样:-
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");
}
这将确保用于源的 url 在 xap 更改时始终更改.您遇到的原始代码存在缺陷,因为 xap 仍然可以更改,而无需更改完全未连接的程序集版本号.
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.
这篇关于如何强制重新下载 Silverlight XAP 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!