views:

614

answers:

2

The company I work for has proxies/WAN accelerators between our international sites to cache Intranet web content. I have a Silverlight application being hosted on a server at one location, but being accessed by clients in another location. When the users access the web page hosting the Silverlight app, they get the stale xap file being cached by the proxy and not the latest version from the server. Local users always get the latest xap as their requests are not going through a proxy.

I've tried the various header/metadata techniques mentioned elsewhere to prevent caching, and the containing web page itself is being served up fresh, but I still get the old .xap file. Short of getting our IT admin to disable proxy caching for my site, is there anything I can do make sure the latest xap file get retrieved from the server instead of the proxy? The containing page is ASP.NET.

+2  A: 

What I do is just add a querystring at the end of the path to the xap file. Then when you change the querystring variable, the proxies etc. should see it as a request to a new file. So far this has worked fine for me.

So basically, when embedding an .xap in a straight-up HTML file, you would do this:

<param name="source" value="ClientBin/SilverlightApplication1.xap?cachepreventer=whatevervalue"/>

And then when you deploy a new version, just change "whatevervalue" to something else.

EDIT
If you need to use this technique in many places in your app I would read the querystring value from config and just write it to the page using asp.net. That way you only need to update it in one place when you deploy.

Henrik Söderlund
Perfect! That did the trick, thanks.
Tim Trout
In my SL solution, whatevervalue is timestamp (tick number) of the XAP file on the disk.I have implemented small ASP.NET helper which appends timestamp as a query to name of the file.That way, it is totally automatic and you do not need to update anything anywhere -- just drop XAP into ClientBin and it is automatically refreshed when user tries to fetch it.Then, in ASPX, I have something like: <param name="source" value=" <% = Helper.AppendTimestamp( "ClientBin/SilverlightApp.xap" ) %>" />
Srdjan Jovcic
That's really clever. I might decide to switch to that technique.
Henrik Söderlund
+1  A: 

If you want to make sure every time the xap file is retrieved and you don't want to worry about it - just use <param name="source" value="ClientBin/YourSilverlightapp.xap?<%=Guid.NewGuid().ToString() %>"/>

of course - this lends itself to a heavier cache load. I do like the helper method above though if you only want changes to be propagated to the client.

Adam Tuliper