11/23/2009

How to disable browser caching in web.config

The title says it all. Here's the web.config snippet that will prevent all pages in your web app from being cached by the user's browser:

<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Cache-Control" value="no-cache" />
<add name="Pragma" value="no-cache" />
<add name="Expires" value="-1" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>

These headers will show up in the "HTTP Response Headers" section of IIS. If you're looking for an explanation why you need 3 name-value pairs, here's Microsoft's explanation.

0 comments:

Post a Comment