HttpCachePolicy.SetValidUntilExpires(Boolean) Metodo

Definizione

Specifica se la cache ASP.NET deve ignorare le intestazioni HTTP Cache-Control inviate dal client che invalidano la cache.

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

Parametri

validUntilExpires
Boolean

true se la cache ignora le Cache-Control intestazioni di invalidazione; in caso contrario, false.

Esempio

Nell'esempio di codice seguente viene illustrato come utilizzare il SetValidUntilExpires metodo per indicare che le intestazioni di invalidazione della cache inviate dal client vengono ignorate.

<!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>

Commenti

Il SetValidUntilExpires metodo viene impostato true su automaticamente quando viene utilizzata la direttiva di pagina di alto livello <%@ OutputCache … %> .

Questo metodo viene fornito perché alcuni browser, durante l'aggiornamento di una visualizzazione pagina, inviano intestazioni di invalidazione della cache HTTP al server Web ed eliminano la pagina dalla cache. Quando il parametro validUntilExpires è true, ASP.NET ignora le intestazioni di invalidazione della cache e la pagina rimane nella cache fino alla scadenza.

SetValidUntilExpires è stato introdotto in .NET Framework versione 3.5. Per altre informazioni, vedere Versioni e dipendenze.

Si applica a