HttpCachePolicy.SetValidUntilExpires(Boolean) Methode

Definition

Gibt an, ob der ASP.NET-Cache vom Client gesendete HTTP-Cache-Control-Header ignorieren soll, die den Cache für ungültig erklären.

public:
 void SetValidUntilExpires(bool validUntilExpires);
public void SetValidUntilExpires (bool validUntilExpires);
member this.SetValidUntilExpires : bool -> unit
Public Sub SetValidUntilExpires (validUntilExpires As Boolean)

Parameter

validUntilExpires
Boolean

true, wenn der Cache ungültige Cache-Control-Header ignoriert, andernfalls false.

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie die SetValidUntilExpires Methode verwendet wird, um anzuweisen, dass alle vom Client gesendeten Cache-Ungültigheitsheader ignoriert werden.

<!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>
<!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="VB" 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.

Sub Page_Load(Sender As Object, e As EventArgs)
   ' 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 the ASP.NET cache will " _
      & " ignore the Cache-Control headers sent by the client that invalidate the cache.")
End Sub 'Page_Load

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

Hinweise

Die SetValidUntilExpires Methode wird automatisch festgelegt true , wenn die Seitenrichtlinie auf hoher Ebene <%@ OutputCache … %> verwendet wird.

Diese Methode wird bereitgestellt, da einige Browser beim Aktualisieren einer Seitenansicht HTTP-Cache-Ungültigungsheader an den Webserver senden und die Seite aus dem Cache auswerfen. Wenn der validUntilExpires Parameter lautettrue, ignoriert ASP.NET Cache-Ungültige Kopfzeilen und die Seite bleibt im Cache, bis sie abläuft.

SetValidUntilExpireswird in der .NET Framework Version 3.5 eingeführt. Weitere Informationen finden Sie unter Versionen und Abhängigkeiten.

Gilt für