HttpCachePolicy.SetValidUntilExpires(Boolean) Метод
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Указывает, должен ли кэш ASP.NET игнорировать заголовки HTTP Cache-Control, отправленные клиентом, который недействителен для кэша.
public:
void SetValidUntilExpires(bool validUntilExpires);
public void SetValidUntilExpires(bool validUntilExpires);
member this.SetValidUntilExpires : bool -> unit
Public Sub SetValidUntilExpires (validUntilExpires As Boolean)
Параметры
- validUntilExpires
- Boolean
trueЗначение , Cache-Controlесли кэш игнорирует false заголовки недопустимых данных; в противном случае .
Примеры
В следующем примере кода показано, как использовать SetValidUntilExpires метод, чтобы указать, что заголовки недопустимых кэша, отправленные клиентом, игнорируются.
<!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>
Комментарии
Метод SetValidUntilExpires устанавливается true автоматически при использовании директивы страницы высокого уровня <%@ OutputCache … %> .
Этот метод предоставляется, так как некоторые браузеры при обновлении представления страницы отправляют заголовки недопустимого HTTP-кэша на веб-сервер и вытесняют страницу из кэша. Если параметр validUntilExpires имеет значение true, ASP.NET пропускает заголовки недопустимых кэша, а страница остается в кэше до истечения срока действия.
SetValidUntilExpires представлен в .NET Framework версии 3.5. Дополнительные сведения см. в разделе "Версии и зависимости".