Share via


HttpCachePolicy.SetAllowResponseInBrowserHistory(Boolean) メソッド

定義

allow パラメーターが true の場合、サーバーの HttpCacheability の設定に関係なく、クライアント ブラウザーの履歴キャッシュに応答を格納できるようにします。

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

パラメーター

allow
Boolean

応答を履歴フォルダーに格納するようクライアントのブラウザーに指示する場合は true。それ以外の場合は false。 既定値は、false です。

次のコード例では、 メソッドをオーバーライド SetAllowResponseInBrowserHistory して、カスタム 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>

注釈

が にNoCache設定されている場合、または ExpiresServerAndNoCache HTTP ヘッダーが既定で -1 に設定されている場合HttpCacheability、これはクライアントに履歴フォルダーに応答をキャッシュしないように指示します。これにより、戻る/転送ボタンを使用すると、クライアントは毎回新しいバージョンの応答を要求します。 この動作をオーバーライドするには、 パラメーターを にtrue設定して SetAllowResponseInBrowserHistory メソッドをallow呼び出します。

が または ServerAndNoCache以外NoCacheの値に設定されている場合HttpCacheability、 のいずれかの値allowで メソッドをSetAllowResponseInBrowserHistory呼び出しても効果はありません。

SetAllowResponseInBrowserHistoryは、.NET Framework バージョン 3.5 で導入されています。 詳細については、「.NET Framework のバージョンおよび依存関係」を参照してください。

適用対象