At times you might have a page that you want to cache, but for which different versions are created based on the request. For example, the page might have different output depending on the values passed in the query string.
ASP.NET allows you to cache multiple versions of the same page in the output cache. You can vary the output cache by the following:
The query string in an initial request (HTTP GET).
Control values passed on postback (HTTP POST values).
The HTTP headers passed with a request.
The major version number of the browser making the request.
A custom string in the page. In that case, you create custom code in the Global.asax file to specify the page's caching behavior.
You can cache multiple versions of a page output declaratively using attributes of the directive, and programmatically using the properties and methods of the class.
The directive includes four attributes that enable you to cache multiple versions of page output:
The attribute allows you to vary the cached output depending on the query string.
The attribute allows you to vary the cached output depending on a control value.
The attribute allows you to vary the cached output depending on the request's HTTP header.
The attribute allows you to vary the cached output by browser type or by a custom string that you define.
You must include either the VaryByParam attribute or the VaryByControl attribute in any directive. However, if you do not need to vary your cached output by control or parameters, you can define VaryByParam with its value to None.
The HttpCachePolicy class provides two properties and a method that allow you to programmatically specify the same cache configuration that you can set declaratively. The and properties allow you to specify the query string parameter and header names, respectively, that you want to vary the cache policy by. The method allows you to define custom strings by which to vary the output cache.
TasksHow to: Set the Cacheability of an ASP.NET Page Declaratively
How to: Set a Page's Cacheability Programmatically
How to: Cache Versions of a Page Using Requesting Browser
How to: Cache Versions of a Page Using Parameters
How to: Cache Versions of a Page Using HTTP Headers
How to: Cache Versions of a Page Using Custom Strings
ConceptsCaching ASP.NET Pages
Setting the Cacheability of a Page