HttpCachePolicy.SetValidUntilExpires-Methode
Gibt an, ob der ASP.NET-Cache Cache-Control-HTTP-Header ignorieren sollte, die vom Client gesendet wurden, der den Cache für ungültig erklärt.
Namespace: System.Web
Assembly: System.Web (in system.web.dll)
Syntax
'Declaration
Public Sub SetValidUntilExpires ( _
validUntilExpires As Boolean _
)
'Usage
Dim instance As HttpCachePolicy
Dim validUntilExpires As Boolean
instance.SetValidUntilExpires(validUntilExpires)
public void SetValidUntilExpires (
bool validUntilExpires
)
public:
void SetValidUntilExpires (
bool validUntilExpires
)
public void SetValidUntilExpires (
boolean validUntilExpires
)
public function SetValidUntilExpires (
validUntilExpires : boolean
)
Parameter
- validUntilExpires
true, wenn der Cache ungültige Cache-Control-Header ignoriert, andernfalls false.
Hinweise
Die SetValidUntilExpires-Methode wird automatisch auf true festgelegt, wenn die <%@ OutputCache … %>-Seitendirektive auf hoher Ebene verwendet wird.
Diese Methode steht zur Verfügung, weil einige Browser beim Aktualisieren einer Seitenansicht ungültige HTTP-Cacheheader an den Webserver senden und die Seite aus dem Cache entfernen. Wenn der validUntilExpires-Parameter auf true festgelegt ist, ignoriert ASP.NET ungültige Cacheheader, und die Seite bleibt zwischengespeichert, bis sie abgelaufen ist.
Beispiel
Im folgenden Codebeispiel wird veranschaulicht, wie mithilfe der SetValidUntilExpires-Methode angewiesen wird, dass alle ungültigen, vom Client gesendeten Cacheheader ignoriert werden.
<html>
<head>
<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>
<html>
<head>
<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
Plattformen
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
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
HttpCachePolicy-Klasse
HttpCachePolicy-Member
System.Web-Namespace