How to prevent Firefox from caching or reloading a Silverlight XAP file?

When working with Silverlight, I noticed that Firefox will cache the XAP file, so if I upgrade, the user may be stuck using an outdated version. Is there a way to force the browser to either reload the XAP file each time, or maybe force it only after the update is published? Or is there a setting in the Silverlight configuration that completely prevents the browser from caching the XAP file?

Thanks Jeff

+50
firefox silverlight
Nov 21 '08 at 3:12
source share
17 answers

The query string works fine, but I would not use DateTime.Now because it forces the user to reload the application each time. Instead, we use the following:

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

Thus, all you have to do is increase the version number in the AssemblyInfo.cs file.

+31
Sep 24 '09 at 1:41
source share

The simplest way:

 <param name="source" value="ClientBin/App.xap?<%= DateTime.Now.Ticks %>" /> 
+12
Sep 02 '09 at 13:23
source share

This is what I do in php. You read the date / time of the xap file and add it as a parameter to the download link. Thus, the browser sees new versions of files as new links and, therefore, not in the cache.

 <?php $fdate = date("dHis",filemtime("MyApp.xap")) ?> <param name="source" value="MyApp.xap?=<?php echo $fdate ?>"/> 

Simple and it works. In addition, browsers continue to cache correctly when there are no updates to download.

+6
Dec 10 '09 at 17:39
source share

For me, the best answer is Chris Cairns . I only adapted it a bit by calling ToString and GetHashCode, creating a timestamp id:

 <param name="source" value="ClientBin/App.xap?<%= System.IO.File.GetLastWriteTime(Server.MapPath("ClientBin/App.xap")).ToString().GetHashCode()%>" /> 

It works well!

+5
Jun 10 2018-11-11T00:
source share

You can find Caching for web authors and webmasters . This document discusses the various caches through which the client and server interact (browser, proxy, gateway) and how to control caching.

+4
Nov 21 '08 at 14:57
source share

You can send HTTP headers to prevent caching:

 Cache-control: no-cache Pragma: no-cache 

How you do this depends on the web server you are using.

+3
Nov 21 '08 at 3:49 a.m.
source share

Another solution would be to add a version of the XAP file rather than a timestamp. The timestamp will change every time (may also disable caching). To force it to change only when updating XAP, you need to get some information from the XAP file. I'm still looking that I can use, possibly, the last modified date of the XAP file?

+2
Jul 10 '09 at 0:28
source share

Adding a timestamp for XAP worked for me (I am adding an SL control to javascript, but this can be just as easily done inline):

 var appTimestamp = '<%= System.IO.File.GetLastWriteTime(Server.MapPath("ClientBin/MyApp.xap")) %>'; var source = 'ClientBin/MyApp.xap?appTimestamp=' + appTimestamp; 
+2
Oct 27 '10 at 10:48
source share

This is tested and works:

Put this:

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

Instead of this:

 <param name="source" value="ClientBin/MyXapFile.xap" /> 
+2
Nov 08 2018-11-11T00:
source share

I make this work with a combination of the above suggestions:

  • Set meta tag / pragma http-equiv cache cache attributes to "No-Cache"
  • Use the ASP.NET page to host the silverlight control (as opposed to the html page).
  • Set the Source property of the ASP.NET Silverlight control in the code behind by adding a timestamp to the .xap URL, for example.

    Silverlight1.Source = "ClientBin / MyApplication.xap?" + DateTime.Now.ToString ("dd-MM-yy-HH: mm: ss");

+1
May 28 '09 at 9:02 a.m.
source share

You can add the source url in the object tag with the date of the last XAP file. Check out the code on my blog .

+1
Feb 01 2018-10-01
source share

We are also in the same situation in which we want to control when the .XAP file is uploaded to the browser.

The approach you can take is to use Silverlight Isolated Storage as a β€œcache” to store your .XAP files.

Check out this blog: Isolated Storage in the Silverlight Object Cache

0
Nov 21 '08 at 20:12
source share

Super simple idea: just add a fake query string in url.

 <param name="source" value="app.xap?r12345"/> 

Most servers should ignore it and work properly with the server file - it depends on your server. If you are really smart, you can make a dynamic hosting page and automatically add the query string of quantity or date to the query string. This ensures that you get caching whenever you want, but force it to load on change.

Ideally, your server should do this for you. But if not ...

0
Nov 21 '08 at 23:13
source share

I had this problem, so now when I launch a new application, I install the build version 0.0.0.1 and just update it one at a time on each deployment, it seems to have solved it for me. Then just set it to 1.0.0.0 at release.

0
Nov 26 '08 at 11:54
source share

So far, the only solution that I have discovered when a problem occurs is to clear the Firefox cache.

A better solution would be much better.

0
Jan 23 '09 at 5:12
source share

I am using this solution

 <object id="Xaml1" data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%"> <%––<param name="source" value="ClientBin/SilverlightApp.xap"/>––%> <% string orgSourceValue = @"ClientBin/SilverlightApp.xap"; string param; if (System.Diagnostics.Debugger.IsAttached) param = "<param name=\"source\" value=\"" + orgSourceValue + "\" />"; else { string xappath = HttpContext.Current.Server.MapPath(@"") + @"\" + orgSourceValue; DateTime xapCreationDate = System.IO.File.GetLastWriteTime(xappath); param = "<param name=\"source\" value=\"" + orgSourceValue + "?ignore=" + xapCreationDate.ToString() + "\" />"; } Response.Write(param); %> <param name="onError" value="onSilverlightError" 
0
Sep 01 '11 at 17:25
source share

The idea of ​​a query string doesn't work for me in Silverlight 4. The server seems to cache the damn xap (although not an aspx file). The solution that works in SL4 is to go to the properties of your Silverlight project, go to the assembly information, and put in the version.

-one
May 26 '10 at 5:22
source share



All Articles