Prevent Silverlight 3 from caching while debugging

我怕爱的太早我们不能终老 提交于 2019-12-12 10:34:04

问题


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?


回答1:


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




回答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);



回答3:


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.




回答4:


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)




回答5:


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.




回答6:


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




回答7:


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




回答8:


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"
   ...
   />


来源:https://stackoverflow.com/questions/1777797/prevent-silverlight-3-from-caching-while-debugging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!