How to: Set a Page's Cacheability Programmatically
The cacheability of a page or user control refers to whether a page can be cached on a device during the page's response life cycle. Devices that can cache a page include the browser making the request, the Web server responding to the request, and any cache-capable devices, such as proxy servers, that are in the request or response stream.
You can set cacheability programmatically if your application will determine cacheability based on run-time conditions, such as reading the request header. For more information, see Setting the Cacheability of a Page.
To set a page's cacheability programmatically
The following code sets the Cache-Control HTTP header to Public.
If you pass either NoCache or ServerAndNoCache to the SetCacheability method to prevent a requesting browser from caching a page in its History folder, any time a user clicks a back or forward button, a new version of the response will be requested. You can override this behavior conditionally by calling the SetAllowResponseInBrowserHistory method on the Cache property and passing true for the allow parameter.