boomhauer boomhauer - 1 year ago 84
ASP.NET (C#) Question

51degrees and iis caching, mvc3, potential issue with output

I've noticed this during debugging and want to make sure it wont happen in production:

I've implemented a mobile version of my website, using the 51degrees library with my MVC3 based app. I'm not using a customized url or subdomain, so each request is analysed to see if it is from a mobile browser before returning the normal or mobile versions of the html.

During debugging I noticed that IIS will sometimes cache the output of the page. I only saw this happen on the home page. Whenever it was cached, the same content was served up to both mobile and desktop browsers, so obviously it's wrong.

I'm aware of the number of ways to prevent page caching browser-side, but thought I'd check if there is a specific recommended way to handle this?

Answer Source

Would I be correct in thinking that you're using the same URL for both mobile and non-mobile pages? If so then you will need to use the following setting.

Response.Cache.VaryByHeaders.UserAgent = true;

This will ensure correctly configured caches will store a different version of the page by the useragent string.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download