When working with Silverlight, I\'ve noticed that Firefox will cache the XAP file, so if I do an update, a user may be stuck using an outdated version. Is there a way to fo
Another solution would be to append the version of the XAP file rather than a timestamp. The timestamp would change every time (might as well turn off caching). To get it to only change when the XAP has been updated would be to take some info from the XAP file. Am still looking into what I could use, perhaps the last modified datestamp of the XAP file?
You might find the Caching Tutorial for Web Authors and Webmasters helpful. This document discusses the different caches through which the client and server interact (browser, proxy, gateway) and how caching can be controlled.
This tested and working:
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" />
You could send HTTP headers to prevent it from caching:
Cache-control: no-cache
Pragma: no-cache
How you do this depends on the web server you're using.
Adding the timestamp for the XAP worked for me (I'm adding the SL control in javascript but this could just as easily be done inline):
var appTimestamp = '<%= System.IO.File.GetLastWriteTime(Server.MapPath("ClientBin/MyApp.xap")) %>';
var source = 'ClientBin/MyApp.xap?appTimestamp=' + appTimestamp;
I use 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"