HttpCachePolicy.SetAllowResponseInBrowserHistory(Boolean) 메서드

정의

allow 매개 변수가 true일 경우, 서버의 HttpCacheability 설정에 관계없이 클라이언트 브라우저 History 캐시에서 응답을 사용할 수 있게 합니다.

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

매개 변수

allow
Boolean

History 폴더에 응답을 저장하도록 클라이언트 브라우저에 지시하려면 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>

설명

HttpCacheability 설정되거나 NoCache ServerAndNoCache Expires HTTP 헤더가 기본적으로 -1로 설정되면 클라이언트가 기록 폴더에 응답을 캐시하지 않도록 지시하므로 뒤로/앞으로 단추를 사용할 때 클라이언트는 매번 새 버전의 응답을 요청합니다. 매개 변수가 설정된 메서드를 SetAllowResponseInBrowserHistory 호출하여 이 동작을 재정의 allow 할 수 있습니다 true.

값이 아닌 NoCache 값으로 설정되거나 ServerAndNoCache값 중 하나를 allow 사용하여 메서드를 SetAllowResponseInBrowserHistory 호출하는 경우 HttpCacheability 아무런 효과가 없습니다.

SetAllowResponseInBrowserHistory .NET Framework 버전 3.5에서에서 도입 되었습니다. 자세한 내용은 버전 및 종속성을 참조하세요.

적용 대상