HttpResponseSubstitutionCallback Делегат

Определение

Представляет метод, который обрабатывает подстановку пост-кэша.

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 

Параметры

context
HttpContext

Объект HttpContext, содержащий сведения о HTTP-запросе для страницы с элементом управления, для которого требуется подстановка пост-кэша.

Возвращаемое значение

Содержимое вставлено в кэш откликов перед отправкой клиенту.

Примеры

В следующем примере кода показано, как программно добавить Substitution элемент управления на кэшированную в выходные данные веб-страницу. При загрузке страницы текущие дата и время отображаются для пользователя в метке. Этот раздел страницы кэшируется и обновляется каждые 60 секунд. При выполнении Substitution элемента управления он вызывает GetCurrentDateTime метод , который должен соответствовать сигнатуре делегата HttpResponseSubstitutionCallback . Строка, возвращаемая методом GetCurrentDateTime , отображается пользователю. Этот раздел страницы не кэшируется и обновляется при каждом обновлении страницы. Свойство MethodNameSubstitution элемента управления получает или задает имя метода обратного вызова.

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

Комментарии

Делегат HttpResponseSubstitutionCallback в сочетании с методом WriteSubstitution используется для отрисовки содержимого после кэширования Substitution элементов управления и AdRotator .

Substitution Для элемента управления используйте MethodName свойство , чтобы указать имя метода обратного вызова, вызываемого при выполнении Substitution элемента управления . Указанный метод обратного вызова должен быть статическим методом на странице или в пользовательском элементе управления, который содержит элемент Substitution управления . Подпись метода обратного вызова должна соответствовать сигнатуре делегата HttpResponseSubstitutionCallbackHttpContext , который принимает параметр и возвращает строку.

AdRotator Для элемента управления отрисовка не зависит от кэширования страницы, если для AdCreated события не указан обработчик событий. Если обработчик событий отсутствует AdCreated , для отображения содержимого используется подстановка после кэширования AdRotator .

Методы расширения

GetMethodInfo(Delegate)

Получает объект, представляющий метод, представленный указанным делегатом.

Применяется к

См. также раздел