强制浏览器在更新后重新加载Silverlight xap

时间:2009-11-12 14:39:03

标签: c# silverlight deployment caching xap

我将Silverlight控件打包并部署到SharePoint Web部件。我推送更新后,浏览器加载新版本的控件时遇到问题。我正在更新我的xap项目的程序集和文件版本,但似乎并不重要。让浏览器加载新xap的唯一方法是进入并删除临时Internet文件。对我来说,在开发过程中,没关系,但我需要在生产之前找到解决方案。有什么想法吗?

5 个答案:

答案 0 :(得分:37)

这与浏览器处理资源请求的方式有关。 Flash有类似的问题,有几个解决方法。

这是一个article,详细说明了问题和可能的解决方案。

我建议做这样的事情:

假设您的HTML中有xap:

<param name="source" value="ClientBin/myApp.xap"/>

我会对其进行版本设置,因此每当您执行推送时,您都会更改版本号。例如:

<param name="source" value="ClientBin/myApp.xap?ver=1"/>

答案 1 :(得分:2)

大!甚至在Windows Phone开发中工作。

我已经说出了这句话:

NavigationService.Navigate(new Uri("/Game.xaml?versao="+version, UriKind.RelativeOrAbsolute));

然后覆盖方法OnNavigatedTo

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    base.OnNavigatedTo(e);
    string var;
    if (NavigationContext.QueryString.TryGetValue("version", out var))
    {
        ...
    }
}

答案 2 :(得分:2)

运行.XAP缓存并不罕见,这意味着每次部署新版本的Silverlight应用程序时,浏览器都不会下载更新的.XAP文件。

一种解决方案可能是更改IIS属性。您可以按照以下步骤为.XAP文件启用“启用内容过期HTTP标头”选项:

Open IIS Manager
Go to “Default Web Site” and find web site for your Silverlight project.
Find the .XAP file under ClientBin.
Go to the properties page of the .XAP file, on HTTP Headers Tab, Turn on “Enable Content Expiration”, click the “Expire Immediately” radio button.
Save the changes.

这样,当您刷新页面而不必关闭浏览器时,将下载最新的.XAP(仅当有最新的.XAP文件时)。

希望这有帮助!

答案 3 :(得分:1)

将以下web.config放入ClientBin

<configuration>
  <system.webServer>
    <staticContent>
      <clientCache cacheControlMaxAge="0.00:00:01" cacheControlMode="UseMaxAge"/>
    </staticContent>
  </system.webServer>
</configuration>

答案 4 :(得分:0)

始终如一,这里提到的解决方案和其他帖子对我没有帮助。 最后,我要做的是将.xap和.svc文件分别从我的Release版本分别复制到ClientBin和Service部署文件夹。

相关问题