Export (0) Print
Expand All

HttpCachePolicy.SetValidUntilExpires Method

Specifies whether the ASP.NET cache should ignore HTTP Cache-Control headers sent by the client that invalidate the cache.

Namespace: System.Web
Assembly: System.Web (in system.web.dll)

public void SetValidUntilExpires (
	bool validUntilExpires
)
public void SetValidUntilExpires (
	boolean validUntilExpires
)
public function SetValidUntilExpires (
	validUntilExpires : boolean
)
Not applicable.

Parameters

validUntilExpires

true if the cache ignores Cache-Control invalidation headers; otherwise, false.

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.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>ASP.NET Example</title>
<script language="C#" runat="server">

// 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.
   Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
   // Set the VaryByHeaders attribute with the value Accept-Language to true.
   Response.Cache.VaryByHeaders["Accept-Language"] = true;
   // ASP.NET ignores cache invalidation headers and the page remains in 
   // the cache until it expires.
   Response.Cache.SetValidUntilExpires(true);
   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.");
}

</script>
</head>
<body></body>
</html>

// 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 Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft