HttpCachePolicy.SetAllowResponseInBrowserHistory(Boolean) Methode

Definition

Macht die Antwort im Verlaufscache des Clientbrowsers ungeachtet der auf dem Server vorgenommenen HttpCacheability-Einstellung verfügbar, wenn der allow-Parameter true ist.

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

Parameter

allow
Boolean

true, wenn der Clientbrowser Antworten im Verlaufsordner speichern soll, andernfalls false. Der Standardwert ist false.

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie Die SetAllowResponseInBrowserHistory -Methode überschrieben wird, um den Client anweisen, die Antworten in seinem Verlauf in einem benutzerdefinierten HttpCachePolicyzu speichern.

<%@ 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>

Hinweise

Wenn HttpCacheability auf NoCache festgelegt ist oder ServerAndNoCache der Expires HTTP-Header standardmäßig auf -1 festgelegt ist. Dies weist den Client an, keine Antworten im Ordner Verlauf zwischenzuspeichern, sodass der Client bei Verwendung der Zurück/Vorwärts-Schaltflächen jedes Mal eine neue Version der Antwort anfordert. Sie können dieses Verhalten überschreiben, indem Sie die SetAllowResponseInBrowserHistory -Methode aufrufen, wobei der allow Parameter auf festgelegt ist true.

Wenn HttpCacheability auf andere Werte als NoCache oder ServerAndNoCachefestgelegt ist, hat das Aufrufen der SetAllowResponseInBrowserHistory Methode mit beiden Werten für allow keine Auswirkung.

SetAllowResponseInBrowserHistorywird in der .NET Framework Version 3.5 eingeführt. Weitere Informationen finden Sie unter Versionen und Abhängigkeiten.

Gilt für: