HttpResponseSubstitutionCallback Delegar

Definição

Representa o método que gere a substituição pós-cache.

public delegate System::String ^ HttpResponseSubstitutionCallback(HttpContext ^ context);
public delegate string HttpResponseSubstitutionCallback(HttpContext context);
type HttpResponseSubstitutionCallback = delegate of HttpContext -> string
Public Delegate Function HttpResponseSubstitutionCallback(context As HttpContext) As String 

Parâmetros

context
HttpContext

O HttpContext que contém a informação de pedido HTTP para a página com o controlo que requer substituição pós-cache.

Devolver Valor

O conteúdo inserido na resposta em cache antes de ser enviado ao cliente.

Exemplos

O exemplo de código seguinte demonstra como adicionar um Substitution controlo programaticamente a uma página Web em cache de saída. Quando a página carrega, a data e hora atuais são apresentadas ao utilizador numa etiqueta. Esta secção da página é armazenada em cache e atualizada a cada 60 segundos. Quando o Substitution controlo é executado, chama o GetCurrentDateTime método, que deve corresponder à assinatura do HttpResponseSubstitutionCallback delegado. A cadeia devolvida pelo GetCurrentDateTime método é apresentada ao utilizador. Esta secção da página não está em cache e é atualizada sempre que a página é atualizada. A MethodName propriedade do Substitution controlo recebe ou define o nome do método de callback.

<%@ outputcache duration="60" varybyparam="none" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server" language="C#">  
  
  void Page_Load(object sender, System.EventArgs e)
  {
    // Programmatically create a Substitution control.
    Substitution Substitution1 = new Substitution();
    
    // Specify the callback method.
    Substitution1.MethodName = "GetCurrentDateTime";
    
    // Add the Substitution control to the controls
    // collection of PlaceHolder1.
    PlaceHolder1.Controls.Add (Substitution1);        

    // Display the current date and time in the label.
    // Output caching applies to this section of the page.
    CachedDateLabel.Text = DateTime.Now.ToString();    
  }
  
  // The Substitution control calls this method to retrieve
  // the current date and time. This section of the page
  // is exempt from output caching. 
  public static string GetCurrentDateTime (HttpContext context)
  {
    return DateTime.Now.ToString ();
  }
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
  <title>Substitution Class Example</title>
</head>
<body>
  <form id="Form1" runat="server">
  
    <h3>Substitution Constructor Example</h3>  
    
    <p>This section of the page is not cached:</p>
    <asp:placeholder id="PlaceHolder1"
      runat="Server">
    </asp:placeholder>
    
    <br />
    
    <p>This section of the page is cached:</p>
    
    <asp:label id="CachedDateLabel"
      runat="Server">
    </asp:label>
    
    <br /><br />
    
    <asp:button id="RefreshButton"
      text="Refresh Page"
      runat="Server">
    </asp:button>     

  </form>
</body>
</html>
<%@ outputcache duration="60" varybyparam="none" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server" language="VB">  
  
  Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    ' Programmatically create a Substitution control.
    Dim Substitution1 As New Substitution
    
    ' Specify the callback method.
    Substitution1.MethodName = "GetCurrentDateTime"
    
    ' Add the Substitution control to the controls
    ' collection of PlaceHolder1.
    PlaceHolder1.Controls.Add(Substitution1)
    
    ' Display the current date and time in the label.
    ' Output caching applies to this section of the page.
    CachedDateLabel.Text = DateTime.Now.ToString()
  End Sub
  
  ' The Substitution control calls this method to retrieve
  ' the current date and time. This section of the page
  ' is exempt from output caching. 
  Shared Function GetCurrentDateTime(ByVal context As HttpContext) As String
    Return DateTime.Now.ToString()
  End Function
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
  <title>Substitution Constructor Example</title>
</head>
<body>
  <form id="Form1" runat="server">
  
    <h3>Substitution Constructor Example</h3>  
    
    <p>This section of the page is not cached:</p>
    <asp:placeholder id="PlaceHolder1"
      runat="Server">
    </asp:placeholder>
    
    <br />
    
    <p>This section of the page is cached:</p>
    
    <asp:label id="CachedDateLabel"
      runat="Server">
    </asp:label>
    
    <br /><br />
    
    <asp:button id="RefreshButton"
      text="Refresh Page"
      runat="Server">
    </asp:button>     

  </form>
</body>
</html>

Observações

O HttpResponseSubstitutionCallback delegado, em combinação com o WriteSubstitution método, é usado para renderizar conteúdo pós-cache para os Substitution controlos e.AdRotator

Para o Substitution controlo, use a MethodName propriedade para especificar o nome do método de callback a invocar quando o Substitution controlo for executado. O método de callback que especifica deve ser um método estático na página ou no controlo de utilizador que contém o Substitution controlo. A assinatura do método de callback deve corresponder à assinatura de um HttpResponseSubstitutionCallback delegado que recebe um HttpContext parâmetro e devolve uma string.

Para o AdRotator controlo, a renderização é independente da cache da página, a menos que seja fornecido um gestor de eventos para o AdCreated evento. Se não houver AdCreated gestor de eventos, é usada substituição pós-cache para renderizar o AdRotator conteúdo.

Métodos da Extensão

Name Description
GetMethodInfo(Delegate)

Obtém um objeto que representa o método representado pelo delegado especificado.

Aplica-se a

Ver também