请单击以进行评分并提供反馈
MSDN
MSDN Library
.NET 开发
.NET Framework
 SetAllowResponseInBrowserHistory 方法

  开启低带宽视图
此页面仅适用于
Microsoft Visual Studio 2008/.NET Framework 3.5

同时提供下列产品的其他版本:
.NET Framework 类库
HttpCachePolicy..::.SetAllowResponseInBrowserHistory 方法

更新:2007 年 11 月

allow 参数为 true 时,将使响应在客户端浏览器“历史记录”缓存中可用,而不论服务器上所做的 HttpCacheability 设置是什么。

命名空间:  System.Web
程序集:  System.Web(在 System.Web.dll 中)

Visual Basic(声明)
Public Sub SetAllowResponseInBrowserHistory ( _
    allow As Boolean _
)
Visual Basic (用法)
Dim instance As HttpCachePolicy
Dim allow As Boolean

instance.SetAllowResponseInBrowserHistory(allow)
C#
public void SetAllowResponseInBrowserHistory(
    bool allow
)
Visual C++
public:
void SetAllowResponseInBrowserHistory(
    bool allow
)
J#
public void SetAllowResponseInBrowserHistory(
    boolean allow
)
JScript
public function SetAllowResponseInBrowserHistory(
    allow : boolean
)

参数

allow
类型:System..::.Boolean

true 指示客户端浏览器将响应存储在“历史记录”文件夹中,否则为 false。默认值为 false

HttpCacheability 设置为 NoCacheServerAndNoCache 时,Expires HTTP 标头默认设置为 -1,这样就会告知客户端不要将响应缓存在“历史记录”文件夹中,这样,使用后退/前进按钮时,客户端每次都请求一个新的响应版本。通过在将 allow 参数设置为 true 的情况下调用 SetAllowResponseInBrowserHistory 方法,您可以重写此行为。

如果将 HttpCacheability 设置为除 NoCacheServerAndNoCache 以外的值,则使用 allow 的任一个值调用 SetAllowResponseInBrowserHistory 方法都将无效。

.NET Framework 3.5 版中引入了 SetAllowResponseInBrowserHistory。有关更多信息,请参见 .NET Framework 3.5 体系结构

下面的代码示例演示如何重写 SetAllowResponseInBrowserHistory 方法,以便在自定义的 HttpCachePolicy 中指示客户端将响应存储在它的历史记录中。

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

C#
<%@ 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  >
  <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 Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

.NET Framework

受以下版本支持:3.5、3.0、2.0、1.1
社区内容   什么是社区内容?
添加新内容 RSS  批注
Processing
© 2009 Microsoft Corporation 版权所有。 保留所有权利  |  商标  |  隐私权声明
Page view tracker