HttpResponseSubstitutionCallback Delegasikan

Definisi

Mewakili metode yang menangani substitusi pasca-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 

Parameter

context
HttpContext

HttpContext yang berisi informasi permintaan HTTP untuk halaman dengan kontrol yang memerlukan substitusi pasca-cache.

Tampilkan Nilai

Konten yang disisipkan ke dalam respons cache sebelum dikirim ke klien.

Contoh

Contoh kode berikut menunjukkan cara menambahkan Substitution kontrol secara terprogram ke halaman Web yang di-cache output. Saat halaman dimuat, tanggal dan waktu saat ini ditampilkan kepada pengguna dalam label. Bagian halaman ini di-cache dan diperbarui setiap 60 detik. Substitution Ketika kontrol dijalankan, kontrol memanggil GetCurrentDateTime metode , yang harus cocok dengan tanda tangan untuk HttpResponseSubstitutionCallback delegasi. String yang dikembalikan oleh GetCurrentDateTime metode ditampilkan kepada pengguna. Bagian halaman ini tidak di-cache dan diperbarui setiap kali halaman disegarkan. Properti MethodNameSubstitution kontrol mendapatkan atau mengatur nama metode panggilan balik.

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

Keterangan

HttpResponseSubstitutionCallback Delegasi, dalam kombinasi dengan WriteSubstitution metode , digunakan untuk merender konten pasca-cache untuk Substitution kontrol dan AdRotator .

Substitution Untuk kontrol, gunakan MethodName properti untuk menentukan nama metode panggilan balik yang akan dipanggil saat Substitution kontrol dijalankan. Metode panggilan balik yang Anda tentukan harus merupakan metode statis pada halaman atau pada kontrol pengguna yang berisi Substitution kontrol. Tanda tangan untuk metode panggilan balik harus cocok dengan tanda tangan untuk HttpResponseSubstitutionCallback delegasi yang mengambil HttpContext parameter dan mengembalikan string.

AdRotator Untuk kontrol, penyajian tidak bergantung pada penembolokan halaman kecuali penanganan aktivitas disediakan untuk peristiwa tersebutAdCreated. Jika tidak ada AdCreated penanganan aktivitas, substitusi pasca-cache digunakan untuk merender AdRotator konten.

Metode Ekstensi

GetMethodInfo(Delegate)

Mendapatkan objek yang mewakili metode yang diwakili oleh delegasi yang ditentukan.

Berlaku untuk

Lihat juga