HttpCachePolicy.SetAllowResponseInBrowserHistory(Boolean) Метод
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Делает ответ доступным в кэше журнала браузера клиента независимо от HttpCacheability параметра, сделанного на сервере, если allow параметр имеет значение true.
public:
void SetAllowResponseInBrowserHistory(bool allow);
public void SetAllowResponseInBrowserHistory(bool allow);
member this.SetAllowResponseInBrowserHistory : bool -> unit
Public Sub SetAllowResponseInBrowserHistory (allow As Boolean)
Параметры
- allow
- Boolean
true для перенаправления клиентского браузера для хранения ответов в папке журнала; в противном случае false. Значение по умолчанию — false.
Примеры
В следующем примере кода показано, как переопределить SetAllowResponseInBrowserHistory метод для перенаправления клиента для хранения ответов в журнале в пользовательском режиме HttpCachePolicy.
<%@ Page language="c#" AutoEventWireup="true" %>
<!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>HttpCachePolicy - SetAllowResponseInBrowserHistory - C# Example</title>
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
// When HttpCacheability is set to NoCache or ServerAndNoCache
// the Expires HTTP header is set to -1 by default. This instructs
// the client to not cache responses in the History folder. Thus,
// each time you use the back/forward buttons, the client requests
// a new version of the response.
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache);
// Override the ServerAndNoCache behavior by setting the SetAllowInBrowserHistory
// method to true. This directs the client browser to store responses in
// its History folder.
HttpContext.Current.Response.Cache.SetAllowResponseInBrowserHistory(true);
// Display the DateTime value.
Label1.Text = DateTime.Now.ToLongTimeString();
}
</script>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>HttpCachePolicy - SetAllowResponseInBrowserHistory - C# Example</h3>
<p>Click the Submit button a few times, and then click the Browser's Back button.<br />
The page should be stored in the Browser's History folder</p>
<p>Time: <asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red" /></p>
<asp:Button id="Button1" runat="server" Text="Submit" />
</form>
</body>
</html>
<%@ Page language="VB" AutoEventWireup="true" %>
<!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>HttpCachePolicy - SetAllowResponseInBrowserHistory - Visual Basic .NET Example</title>
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' When HttpCacheability is set to NoCache or ServerAndNoCache
' the Expires HTTP header is set to -1 by default. This instructs
' the client to not cache responses in the History folder. Thus,
' each time you use the back/forward buttons, the client requests
' a new version of the response.
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache)
' Override the ServerAndNoCache behavior by setting the SetAllowInBrowserHistory
' method to true. This directs the client browser to store responses in
' its History folder.
HttpContext.Current.Response.Cache.SetAllowResponseInBrowserHistory(True)
' Display the DateTime value.
Label1.Text = DateTime.Now.ToLongTimeString()
End Sub
</script>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>HttpCachePolicy - SetAllowResponseInBrowserHistory - Visual Basic .NET</h3>
<p>Click the Submit button a few times, and then click the Browser's Back button.<br />
The page should be stored in the Browser's History folder</p>
<p>Time: <asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red" /></p>
<asp:Button id="Button1" runat="server" Text="Submit" />
</form>
</body>
</html>
Комментарии
Если HttpCacheability задано NoCache значение или ServerAndNoCacheExpires заголовок HTTP по умолчанию имеет значение -1; клиент не кэширует ответы в папке журнала, чтобы при использовании кнопок назад и вперед клиент запрашивал новую версию ответа каждый раз. Это поведение можно переопределить, вызвав SetAllowResponseInBrowserHistory метод с заданным параметром allowtrue.
Если HttpCacheability задано значение, отличное NoCache от или ServerAndNoCacheвызывающее метод с либо значением, SetAllowResponseInBrowserHistory не имеет никакого allow эффекта.
SetAllowResponseInBrowserHistory представлен в .NET Framework версии 3.5. Дополнительные сведения см. в разделе "Версии и зависимости".