|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
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.
To set a page's cacheability programmatically
In the page's code, call themethod on the property of the object.
The following code sets the Cache-Control HTTP header to.
If you pass eitheror 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 method on the property and passing true for the allow parameter.
If you set cacheability to any value other than NoCache or ServerAndNoCache, ASP.NET ignores the value set by the SetAllowResponseInBrowserHistory method.