ASP.NET output caching by user agent
I received this question from ObiShawn:
"Does .NET/IIS output caching vary by user-agent?"
Good question Shawn! By default, the output cache stores the same version of the page for all users, regardless of their user agent. To change this behavior, add the VaryByHeader parameter to your OutputCache declaration:
<%@ OutputCache Duration="60" VaryByParam="*" VaryByHeader="User-Agent" %>
This is probably a good idea to include in your OutputCache directive, because ASP.NET will render controls differently to some browsers.aspx). It modify the output HTML based on the browsers capabilities.
If your site is only targeting the latest generation of browser, you can probably avoid varying by user agent.
One last note. You can include multiple headers in the VaryByHeader parameter. Simply separate them with semi-colons.
For more information about OutputCaching, this is a great article.
Like this post? Please share it!