3

I'm struggling with my IIS setup regarding caching, here's a brief description of my problem:

I'm making a site for mobile and non-mobile, sharing the same controllers. IE: mysite/page will serve either mysite/page.cshtml, or mysite/M/page.cshtml, depending on the device.

Here's the catch, it worked fine with my local and integration environment (cassiini and iis 6), but on another machine (2008r2/iis 7.5), apparently there is an aggressive server-side caching policy:

  • If I access the website from a desktop machine, I have the correct pages (desktop version)
  • If now I use my mobile phone to access the site, I will have the desktop version, (which implies a server-side cache, my phone is not using the same network).

On the contrary, if I were to restart the server and access the site using my phone first, then I will get the mobile version on my desktop (only for the pages I already visited of course).

I tried 2 solutions so far:

Disabling OutputCache from my Web.config:

<httpModules>
  [..]
  <remove name="OutputCache" />
</httpModules>

And unchecking "Enable output cache" in "Output Caching" for my site in IIS.

What's bugging me is that I do not have this problem with my other server (iis 6.0), although caching is enabled on this one, which leads me to think it is related to iis 7 caching addition.

My question is simple: how does one disable server-side caching on IIS 7.5?

Thanks in advance for your iis lights!

Found it!

Sorry guys you could not really guess that one, I extend RazorViewEngine (actually I used a sample mobile mvc3 template app), and this class overrides FindView, it is supposed to take into account a useCache parameter, but apparently no matter how I configure IIS, it was set to true with iis7. I set it to false everywhere. I'll look into appropriate tuning of that parameter tomorrow.

public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)

Thanks for your help guys, I have a good understanding of all the caching possibilities with IIS now ;). It's interesting that this behaves differently with IIS 7.0 (IIS6 and Cassiini were consistent).

Edit:

More info: http://aspnet.codeplex.com/workitem/8201?PendingVoteId=8201 , it is related to debug/release working of FindView.

This was my exact problem: http://aspnet.codeplex.com/workitem/8201?PendingVoteId=8201

rick schott
  • 21,012
  • 5
  • 52
  • 81
troebr
  • 31
  • 1
  • 1
  • 4

3 Answers3

1

If you are speaking to static types such as images and such you can add this to your web.config

 <staticContent>
  <clientCache cacheControlMode="DisableCache"/>
</staticContent>

Update:

Here is a link

This link talks in detail about what you want to do.

Etch
  • 3,044
  • 25
  • 31
1

As Rick said, you need to profile this first. A quick test though would be to implement a no-cache controller as I outlined here: Disable browser cache for entire ASP.NET website

Community
  • 1
  • 1
Adam Tuliper
  • 29,982
  • 4
  • 53
  • 71
  • I did that, no change, however I noted that somehow the non mobile version prevails, as soon as I load a non mobile version of a page, whatever the browser/computer/phone, it's all going to be rendered as a non desktop. – troebr Nov 28 '11 at 18:38
0

I think you are dealing with browser cache. Have you profiled the traffic to see the 304s? You may be chasing the wrong problem.

NOTE: Your cache busting solution has to include the client side as well as the server-side.

rick schott
  • 21,012
  • 5
  • 52
  • 81
  • I have that problem when I use separate browsers, this excludes browser cache issues. (browser2 is mobile and gets the page from browser1 which is not mobile) – troebr Nov 28 '11 at 17:53
  • You need to monitor the HTTP responses to know what is happening. Looking visually at the pages on different devices isn't very reliable. – rick schott Nov 28 '11 at 17:57
  • I'm trying to disable OutputCache as you suggested, unfortunately I don't know how to monitor the HTTP status code on my android, but I get 200s on the desktop. – troebr Nov 28 '11 at 18:16