Export (0) Print
Expand All

HttpCachePolicy.SetAllowResponseInBrowserHistory Method

Makes the response is available in the client browser History cache, regardless of the HttpCacheability setting made on the server, when the allow parameter is true.

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

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

Parameters

allow

true to direct the client browser to store responses in the History folder; otherwise false. The default is false.

When HttpCacheability is set to NoCache or ServerAndNoCache the Expires HTTP header is by default set to -1; this tells the client not to cache responses in the History folder, so that when you use the back/forward buttons the client requests a new version of the response each time. You can override this behavior by calling the SetAllowResponseInBrowserHistory method with the allow parameter set to true.

If HttpCacheability is set to values other than NoCache or ServerAndNoCache, calling the SetAllowResponseInBrowserHistory method with either value for allow has no effect.

The following code example demonstrates how to override the SetAllowResponseInBrowserHistory method to direct the client to store the responses in its history in a custom HttpCachePolicy.

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

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1

Community Additions

ADD
Show:
© 2014 Microsoft