HttpCachePolicy.SetAllowResponseInBrowserHistory(Boolean) Methode

Definition

Stellt die Antwort im Cache des Clientbrowserverlaufs zur Verfügung, unabhängig von der HttpCacheability Einstellung auf dem Server, wenn der allow Parameter ist true.

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 den Clientbrowser so zu leiten, dass Antworten im Ordner "Verlauf" gespeichert werden; andernfalls false. Der Standardwert lautet false.

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie die SetAllowResponseInBrowserHistory Methode überschreibt, um den Client zum Speichern der Antworten in seinem Verlauf in einer benutzerdefinierten HttpCachePolicyDatei zu überschreiben.

<%@ 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 der NoCache HTTP-Header auf -1 festgelegt ist oder ServerAndNoCache der Expires HTTP-Header standardmäßig auf -1 festgelegt ist. Dadurch wird dem Client mitgeteilt, keine Antworten im Ordner "Verlauf" zwischenzuspeichern, sodass der Client bei jeder Verwendung der Schaltflächen "Zurück/Weiterleiten" eine neue Version der Antwort anfordert. Sie können dieses Verhalten überschreiben, indem Sie die SetAllowResponseInBrowserHistory Methode aufrufen, wobei der allow Parameter auf true.

Wenn HttpCacheability dieser Wert auf andere Werte festgelegt ist als NoCache oder ServerAndNoCache, hat das Aufrufen der SetAllowResponseInBrowserHistory Methode mit einem wert keine allow Auswirkung.

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

Gilt für: