HttpCachePolicy.SetAllowResponseInBrowserHistory(Boolean) Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Faz com que a resposta esteja disponível na cache de Histórico do navegador cliente, independentemente da HttpCacheability configuração feita no servidor, quando o allow parâmetro é true.
public:
void SetAllowResponseInBrowserHistory(bool allow);
public void SetAllowResponseInBrowserHistory(bool allow);
member this.SetAllowResponseInBrowserHistory : bool -> unit
Public Sub SetAllowResponseInBrowserHistory (allow As Boolean)
Parâmetros
- allow
- Boolean
true para direcionar o navegador cliente para armazenar as respostas na pasta Histórico; caso contrário false. A predefinição é false.
Exemplos
O exemplo de código seguinte demonstra como sobrescrever o SetAllowResponseInBrowserHistory método para direcionar o cliente a armazenar as respostas no seu histórico num custom 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>
Observações
Quando HttpCacheability está definido como NoCache ou ServerAndNoCache o Expires cabeçalho HTTP está por defeito definido em -1; isto indica ao cliente para não guardar respostas em cache na pasta Histórico, de modo que, ao usar os botões de retroceder/avançar, o cliente solicite uma nova versão da resposta de cada vez. Pode sobrescrever este comportamento chamando o SetAllowResponseInBrowserHistory método com o allow parâmetro definido em true.
Se HttpCacheability for definido para valores diferentes de NoCache ou ServerAndNoCache, chamar o SetAllowResponseInBrowserHistory método com qualquer um dos valores para allow não tem efeito.
SetAllowResponseInBrowserHistory é introduzido na versão 3.5 do .NET Framework. Para mais informações, consulte Versões e Dependências.