Prevent Silverlight 3 from caching while debugging
Asked Answered
H

8

9

I'm assuming the issue I'm having is related to caching. Code changes I make are not getting picked up when I debug. Most times I get served a previous version of the app. How do I prevent this from happening?

Highoctane answered 22/11, 2009 at 4:20 Comment(2)
How are you debugging, running in Visual Studio? Do you have a test web site in the solution? What browser are you hosting the SL in?Hydrosol
Hello, is this mic on?? ... You have 4 upvotes on this question but you haven't responded to my questions above nor have you responded to any of those who have taken the time to attempt to answer your question.Hydrosol
D
2

Try to add to the page that hosts Silverlight application on Page_Load:

      Response.Cache.SetExpires(DateTime.Now.AddSeconds(-100));
      Response.Cache.SetCacheability(HttpCacheability.NoCache);
Disabled answered 29/11, 2009 at 15:28 Comment(0)
E
2

Ctrl+F5 is an easy way to refresh a page and clear the cache of that page at the same time - it may help :)

Ehrman answered 16/12, 2009 at 16:39 Comment(0)
T
1

Append a "version" querystring to your XAP Url, something like:

http://localhost:1234/ClientBin/my_silverlight_app.xap?v=1.0.287.5361

This will trick the browser (and many web servers) to think that this is a different file. And when the cache problem appears again, increase the number.

If you then want to employ proper caching, do it on the server-side with OutputCache directives.

Tonguetied answered 19/12, 2009 at 21:42 Comment(0)
Z
0

As far as I see, this seems to be a problem with Firefox - when I used IE8, this didn't happen to me (I realize this may open its own can of worms, but at least for debugging and testing Silverlight, IE is much better)

Zhukov answered 22/11, 2009 at 9:54 Comment(0)
A
0

I have not had any issues with Silverlight assemblies getting cached - you might want to try debugging the HTTP requests that go back and forth, to see if maybe your server is instead returning incorrect information to the browser (e.g. a "not modified" response).

For general no-cache behavior, the only reliable method I have found is to turn off caching in the browser.

For IE, this has been the only reliable option - otherwise, even if proper no-cache headers are sent, certain things are still cached (specifically, dynamically loaded resources which are accessed via Javascript XmlHttpRequest). I have not specifically had issues with Silverlight getting cached when it should not, though - IE has always loaded the latest updates even if cache is enabled.

Firefox has been much more problematic - even when disabling cache, it still sometimes caches XmlHttpRequest-loaded resources. Manually hitting Refresh a few times has been the only solution in such a case. Once again, I have had no issues with Silverlight assembles, even if cache is turned on.

Arnie answered 22/11, 2009 at 10:0 Comment(0)
R
0

In Firefox, I use the 'web developer' plugin and simply select to 'disable cache'. Works fine.

Raine answered 24/11, 2009 at 1:8 Comment(3)
I cannot tell this to every user of my website, so I have a better solution for everyone.Evangelinaevangeline
This is for debugging only. You don't need to tell every user of your website, it also breaks the cache implementation for the rest of your users.Raine
Well we do not want caching of old version when we release new version, there is no question of breaking.Evangelinaevangeline
D
0

Firefox 3.5 under Tools has the option for Private Browsing. Click that to disable caching.

Dianoia answered 18/12, 2009 at 0:36 Comment(0)
E
0

Here is how I have done it for flex/flash and silverlight and it works.

Code Behind ASPX or CSHTML

string slUrl = "/ClientBin/MySilverlight.xap";

string filePath = Server.MapPath(slUrl);

FileInfo info = new FileInfo(filePath);

// this will force browser to 
// re download file if file was
// updated
slUrl += "?t=" + info.FileWriteTime.Ticks; 

ASPX or CSHTML

<embed ....
   src="<%= slUrl %>"
   ..
/>

Trick is you have to change url by adding something after ? and make a new arbitrary random query string or use file write time, and for browser, something?t=1 and something?t=2 are two urls and it will not pickup cache if t changes.

Instead of write time, you can also choose any standard config value or you can even simply hardcode your ASPX or HTML and append something after ? that will force browsers to download silverlight xap file again.

<embed ....
   src="/ClientBin/MySilverlight.xap?something-different-each-time"
   ...
   />
Evangelinaevangeline answered 10/1, 2012 at 16:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.