HttpResponseSubstitutionCallback Delegado

Definición

Representa el método que controla la substitución posterior a la caché.

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

HttpContext que contiene la información de la solicitud HTTP correspondiente a la página con el control que requiere la sustitución posterior a la caché.

Valor devuelto

Contenido insertado en la respuesta almacenada en memoria caché antes de su envío al cliente.

Ejemplos

En el ejemplo de código siguiente se muestra cómo agregar un Substitution control mediante programación a una página web almacenada en caché de salida. Cuando se carga la página, la fecha y hora actuales se muestran al usuario en una etiqueta. Esta sección de la página se almacena en caché y se actualiza cada 60 segundos. Cuando se ejecuta el Substitution control, llama al GetCurrentDateTime método , que debe coincidir con la firma del HttpResponseSubstitutionCallback delegado. La cadena devuelta por el GetCurrentDateTime método se muestra al usuario. Esta sección de la página no se almacena en caché y se actualiza cada vez que se actualiza la página. La MethodName propiedad del Substitution control obtiene o establece el nombre del método de devolución de llamada.

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

Comentarios

El HttpResponseSubstitutionCallback delegado, en combinación con el método , se usa para representar contenido posterior a la WriteSubstitution caché para los Substitution controles y AdRotator .

Para el Substitution control, use la MethodName propiedad para especificar el nombre del método de devolución de llamada que se invocará cuando se ejecute el Substitution control. El método de devolución de llamada que especifique debe ser un método estático en la página o en el control de usuario que contiene el Substitution control . La firma del método de devolución de llamada debe coincidir con la firma de un HttpResponseSubstitutionCallback delegado que toma un HttpContext parámetro y devuelve una cadena.

Para el control, la AdRotator representación es independiente del almacenamiento en caché de páginas a menos que se proporcione un controlador de eventos para el AdCreated evento. Si no hay ningún AdCreated controlador de eventos presente, se usa la sustitución posterior a la caché para representar el AdRotator contenido.

Métodos de extensión

GetMethodInfo(Delegate)

Obtiene un objeto que representa el método representado por el delegado especificado.

Se aplica a

Consulte también