Home > English > Having problems with IIS caching your Silverlight application?

Having problems with IIS caching your Silverlight application?

Microsoft has made developing Silverlight applications really easy when using Visual Studio. Once you are finished with your initial version, you want to deploy it and make it available to your clients. Within Visual Studio you can simply perform a Publish operation on your web site that is hosting your Silverlight application.

One of the strongest frustrations that I hear from clients is that when they deploy their application and then make a minor change and redeploy, the end user never sees a changed until the clear their cache on their browser. This makes it look like your software is buggy and that Silverlight is not a stable platform. It is even harder to control this when you are dealing with a multi-tenant style enterprise application where your modules are separate XAP files.

If you have designed your application to have a quick startup and are only bringing down the required XAP files, then the following solution might work for you. In most of the applications that I design, I have a shell XAP and a separate security XAP that are downloaded immediately and once a user has successfully authenticated then I bring down any other required XAPs. I typically use Prism from the Patterns and Practices Team at Microsoft to handle all of this for me but you can do this through MEF as well.

Okay, here are the steps to ensure that your end users never have to clear their cache when using your Silverlight application regardless of how many times you push any new updates.

This solution is based on IIS 7.0 but you can also do this in 6.0 as well.

Go to your Silverlight application in IIS 7.0 and click on the application.

Next double-click on the HTTP Response Headers icon

Next click on the Set Common Headers link on the top right

Finally, check on the Expire Web content checkbox and use the default setting for immediate.

That is all you should have to do to get your application running like a champ. There is the side effect of the application being downloaded every time but if you have mitigated this with good Silverlight design, then you should be okay from a user’s experience perspective. I have seen other solutions that mention versioning your assembly but it doesn’t work so well when all that has changed is a XAP file that is not the controlling shell application.

If you are only dealing with a single XAP and you want some way to get around this, you should read this blog post by Lars Holm Jensen. This only works if you have made modifications to the primary XAP file but is a good solution for your smaller Silverlight applications.

If there is a better solution to the multi-XAP scenario then I would love to hear from you.

Hope this helps!

Categories: English Tags: , , ,
  1. August 29, 2011 at 12:33 pm

    We too are using PRISM to subdivide our SL app in modules.
    To avoid caching I’ve done 2 things

    1 added “Cache-Control: no-cache, must-revalidate, proxy-revalidate” as Custom HTTP-header on the ClientBin folder in IIS (you can put this on the website as well, but the clientbin is enough and other resources in my website will still be cached)
    see http://www.mnot.net/cache_docs for more info

    2 override the ConfigureModuleCatalog in my bootstrapper and add a “?ignore=lastbuildtime_module” to the xapfilename so it looks like http://mydevurl/app/ClientBin/WorkflowModule.xap?ignore=29/08/2011%203:07:59

    because Lars Holm Jensen’s technique only worked for the main xap file and not for the individual module xaps.

    I pass the lastbuildtime_module from my startpage.aspx as a parameter to Silverlight. I just scan my clientbin for xap’s and get the latest WriteTime, this way I’m sure that when 1 of my xaps is changed, the browser will get the latest version.

    This seems to do the trick for our project, although Firefox sometimes gives issues

  2. August 29, 2011 at 12:35 pm

    it should be “avoid caching issues” in stead of “avoid caching” because this technique will still allow the end-user to cache the xaps!

  3. pyskaty
    August 29, 2011 at 2:10 pm

    We developed custom httphandler for serving xap’s and we’re basing on simple if-modified-since request header.

  4. August 29, 2011 at 2:45 pm

    Thanks so much for your input. These are great ideas and I will definitely try out the solution you posted Geert. It is exactly what I am looking for!

    April 6, 2012 at 5:54 am

    Thanks you very much, I have applied this solution and it’s really work. Once again thanks to you.

  6. Ernest
    June 26, 2014 at 11:00 pm

    I’m sorry for being a noob… how can I set the Cache-Control property for a folder in IIS?

  1. August 29, 2011 at 11:11 am
  2. August 29, 2011 at 6:29 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: