次の方法で共有


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 です。

解説

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

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

使用例

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

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

プラットフォーム

Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition

Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。

バージョン情報

.NET Framework

サポート対象 : 3.0,2.0,1.1

参照

関連項目

HttpCachePolicy クラス
HttpCachePolicy メンバ
System.Web 名前空間