HttpCachePolicy.SetValidUntilExpires Method
Assembly: System.Web (in system.web.dll)
The SetValidUntilExpires method is set to true automatically when the high-level <%@ OutputCache … %> page directive is used.
This method is provided because some browsers, when refreshing a page view, send HTTP cache invalidation headers to the Web server and evict the page from the cache. When the validUntilExpires parameter is true, ASP.NET ignores cache invalidation headers and the page remains in the cache until it expires.
The following code example demonstrates how to use the SetValidUntilExpires method to instruct that any cache invalidation headers sent by the client are ignored.
// The following example demonstrates the SetValidUntilExpires method of the
// HttpCachePolicy class. The SetValidUntilExpires method is set to true so
// that the ASP.NET cache ignores the HTTP Cache-Control headers and the page
// remains in the cache until it expires.
void Page_Load(Object sender, EventArgs e)
{
// Set the expiration time for the page.
get_Response().get_Cache().SetExpires(DateTime.get_Now().AddSeconds(60));
// Set the VaryByHeaders attribute with the value Accept-Language to true.
get_Response().get_Cache().get_VaryByHeaders().set_Item(
"Accept-Language" , true );
// ASP.NET ignores cache invalidation headers and the page remains in
// the cache until it expires.
get_Response().get_Cache().SetValidUntilExpires(true);
get_Response().Write("The SetValidUntilExpires method is set to true"
+" and ASP.NET cache should ignore the Cache-Control headers sent"
+" by the client that invalidate the cache.");
} //Page_Load
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.