HttpCachePolicy.SetAllowResponseInBrowserHistory(Boolean) Metoda
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Zpřístupní odpověď v mezipaměti historie prohlížeče klienta bez HttpCacheability ohledu na nastavení na serveru, pokud allow je trueparametr .
public:
void SetAllowResponseInBrowserHistory(bool allow);
public void SetAllowResponseInBrowserHistory(bool allow);
member this.SetAllowResponseInBrowserHistory : bool -> unit
Public Sub SetAllowResponseInBrowserHistory (allow As Boolean)
Parametry
- allow
- Boolean
true nasměrovat klientský prohlížeč tak, aby ukládaly odpovědi do složky Historie; jinak false. Výchozí hodnota je false.
Příklady
Následující příklad kódu ukazuje, jak přepsat metodu SetAllowResponseInBrowserHistory nasměrovat klienta k uložení odpovědí v jeho historii ve vlastním 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>
Poznámky
Pokud HttpCacheability je nastavená hodnota hlavičky HTTP nebo NoCacheServerAndNoCache je ve výchozím nastavení nastavená Expires na hodnotu -1. Klient tak nemusí ukládat odpovědi do mezipaměti ve složce Historie, takže když použijete tlačítka zpět/vpřed, klient pokaždé požádá o novou verzi odpovědi. Toto chování můžete přepsat voláním SetAllowResponseInBrowserHistory metody s parametrem nastaveným allow na true.
Pokud HttpCacheability je nastavena na jiné hodnoty než NoCache nebo ServerAndNoCache, volání metody s některou SetAllowResponseInBrowserHistory hodnotou pro allow nemá žádný vliv.
SetAllowResponseInBrowserHistory je zaveden v rozhraní .NET Framework verze 3.5. Další informace naleznete v tématu Verze a závislosti.