HttpResponseSubstitutionCallback Delegato

Definizione

Rappresenta il metodo che gestisce la sostituzione successiva alla memorizzazione nella 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 

Parametri

context
HttpContext

Classe HttpContext contenente le informazioni sulla richiesta HTTP della pagina con il controllo che richiede la sostituzione successiva alla memorizzazione nella cache.

Valore restituito

Contenuto inserito nella risposta memorizzata nella cache prima di essere inviata al client.

Esempio

Nell'esempio di codice seguente viene illustrato come aggiungere un Substitution controllo a livello di codice a una pagina Web memorizzata nella cache di output. Quando la pagina viene caricata, la data e l'ora correnti vengono visualizzate all'utente in un'etichetta. Questa sezione della pagina viene memorizzata nella cache e aggiornata ogni 60 secondi. Quando il controllo viene eseguito, chiama il SubstitutionGetCurrentDateTime metodo, che deve corrispondere alla firma per il HttpResponseSubstitutionCallback delegato. La stringa restituita dal GetCurrentDateTime metodo viene visualizzata all'utente. Questa sezione della pagina non viene memorizzata nella cache e viene aggiornata ogni volta che la pagina viene aggiornata. La MethodName proprietà del Substitution controllo ottiene o imposta il nome del metodo di 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>

Commenti

Il HttpResponseSubstitutionCallback delegato, in combinazione con il WriteSubstitution metodo, viene usato per il rendering del contenuto post-cache per i Substitution controlli e AdRotator .

Per il Substitution controllo, usare la MethodName proprietà per specificare il nome del metodo di callback per richiamare quando il Substitution controllo viene eseguito. Il metodo di callback specificato deve essere un metodo statico nella pagina o nel controllo utente che contiene il Substitution controllo. La firma per il metodo di callback deve corrispondere alla firma per un HttpResponseSubstitutionCallback delegato che accetta un HttpContext parametro e restituisce una stringa.

Per il controllo, il AdRotator rendering è indipendente dalla memorizzazione nella cache della pagina, a meno che non venga fornito un gestore eventi per l'evento AdCreated . Se non è presente alcun AdCreated gestore eventi, viene usata la sostituzione post-cache per eseguire il rendering del AdRotator contenuto.

Metodi di estensione

GetMethodInfo(Delegate)

Ottiene un oggetto che rappresenta il metodo rappresentato dal delegato specificato.

Si applica a

Vedi anche