Freigeben über


HttpCachePolicy.SetAllowResponseInBrowserHistory-Methode

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

Namespace: System.Web
Assembly: System.Web (in system.web.dll)

Syntax

'Declaration
Public Sub SetAllowResponseInBrowserHistory ( _
    allow As Boolean _
)
'Usage
Dim instance As HttpCachePolicy
Dim allow As Boolean

instance.SetAllowResponseInBrowserHistory(allow)
public void SetAllowResponseInBrowserHistory (
    bool allow
)
public:
void SetAllowResponseInBrowserHistory (
    bool allow
)
public void SetAllowResponseInBrowserHistory (
    boolean allow
)
public function SetAllowResponseInBrowserHistory (
    allow : boolean
)

Parameter

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

Hinweise

Wenn HttpCacheability auf NoCache oder auf ServerAndNoCache festgelegt ist, wird der Expires-HTTP-Header standardmäßig auf -1 festgelegt. Dadurch wird der Client angewiesen, Antworten nicht im Verlaufsordner zwischenzuspeichern, sodass er bei jeder Verwendung der Schaltflächen zum Vorwärts- und Zurücknavigieren eine neue Version der Antwort anfordert. Dieses Verhalten kann durch Aufrufen der SetAllowResponseInBrowserHistory-Methode überschrieben werden, wobei der allow-Parameter auf true festgelegt sein muss.

Wenn HttpCacheability auf andere Werte als NoCache oder ServerAndNoCache festgelegt ist, bleibt das Aufrufen der SetAllowResponseInBrowserHistory-Methode mit jedem der beiden Werte für allow wirkungslos.

Beispiel

Im folgenden Codebeispiel wird das Überschreiben der SetAllowResponseInBrowserHistory-Methode veranschaulicht, um den Client anzuweisen, die Antworten im Verlauf in einer benutzerdefinierten HttpCachePolicy zu speichern.

<%@ Page language="VB" AutoEventWireup="true" %>
<HTML>
  <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>
<%@ Page language="c#" AutoEventWireup="true" %>
<HTML>
  <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>

Plattformen

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1

Siehe auch

Referenz

HttpCachePolicy-Klasse
HttpCachePolicy-Member
System.Web-Namespace