HttpCachePolicy.SetValidUntilExpires(Boolean) Methode
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Gibt an, ob der ASP.NET-Cache HTTP-Cache-Control Header ignorieren soll, die vom Client gesendet werden, die den Cache ungültig haben.
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ültigheitsheader Cache-Control 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 true festgelegt, wenn die High-Level-Seitendirektive <%@ OutputCache … %> verwendet wird.
Diese Methode wird bereitgestellt, da einige Browser beim Aktualisieren einer Seitenansicht HTTP-Cache-Ungültigheitsheader an den Webserver senden und die Seite aus dem Cache löschen. Wenn der Parameter validUntilExpirestrue ist, ignoriert ASP.NET Cache-Ungültigheitsheader, und die Seite verbleibt bis zum Ablauf im Cache.
SetValidUntilExpires wird in der .NET Framework Version 3.5 eingeführt. Weitere Informationen finden Sie unter "Versionen und Abhängigkeiten".