HttpCachePolicy.SetAllowResponseInBrowserHistory(Boolean) Metódus

Definíció

A válasz elérhetővé válik az ügyfélböngésző előzmény-gyorsítótárában, függetlenül a HttpCacheability kiszolgálón beállított beállítástól, ha a allow paraméter értéke .true

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

Paraméterek

allow
Boolean

true az ügyfélböngésző irányítása a válaszok tárolására az Előzmények mappában; egyéb esetben false. Az alapértelmezett érték a false.

Példák

Az alábbi példakód bemutatja, hogyan lehet felülbírálni azt a SetAllowResponseInBrowserHistory metódust, amely arra utasítja az ügyfelet, hogy a válaszokat az előzményeiben tárolja egy egyéni HttpCachePolicyfájlban.

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

Megjegyzések

Ha HttpCacheability be van állítva NoCache , vagy ServerAndNoCache a Expires HTTP-fejléc alapértelmezés szerint -1 értékre van állítva; ez azt jelzi az ügyfélnek, hogy ne gyorsítótárazza a válaszokat az Előzmények mappában, így a vissza/továbbítás gomb használatakor az ügyfél minden alkalommal a válasz új verzióját kéri. Ezt a viselkedést felülbírálhatja úgy, hogy meghívja a SetAllowResponseInBrowserHistory metódust a allow paraméter beállításával true.

Ha HttpCacheability nem vagy NoCachenem ServerAndNoCache értékre van beállítva, akkor a SetAllowResponseInBrowserHistory metódus meghívásának allow nincs hatása.

SetAllowResponseInBrowserHistory a .NET-keretrendszer 3.5-ös verziójában kerül bevezetésre. További információ: Verziók és függőségek.

A következőre érvényes: