HttpCachePolicy.SetAllowResponseInBrowserHistory メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > HttpCachePolicy.SetAllowResponseInBrowserHistory メソッドの意味・解説 

HttpCachePolicy.SetAllowResponseInBrowserHistory メソッド

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

名前空間: System.Web
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Sub SetAllowResponseInBrowserHistory
 ( _
    allow As Boolean _
)
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
)

パラメータ

allow

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

解説解説

HttpCacheability が NoCache または ServerAndNoCache に設定されている場合、Expires HTTP ヘッダーは既定で -1 に設定されます。この場合、クライアントは応答を履歴フォルダにキャッシュしません。したがって、ユーザーが [戻る] ボタンまたは [進む] ボタンをクリックした場合、クライアントはそのたびに新しい応答を要求します。この動作をオーバーライドするには、allow パラメータを true に設定して SetAllowResponseInBrowserHistory メソッドを呼び出します。

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

使用例使用例

カスタムの HttpCachePolicy で SetAllowResponseInBrowserHistory メソッドをオーバーライドして、応答を履歴に格納するようクライアントに指示する方法を次のコード例に示します。

<%@ 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>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

HttpCachePolicy.SetAllowResponseInBrowserHistory メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



HttpCachePolicy.SetAllowResponseInBrowserHistory メソッドのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS