Substitution.MethodName Свойство

Определение

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

public:
 virtual property System::String ^ MethodName { System::String ^ get(); void set(System::String ^ value); };
public virtual string MethodName { get; set; }
member this.MethodName : string with get, set
Public Overridable Property MethodName As String

Значение свойства

String

Строка, представляющая имя метода, которое вызывается при исполнении элемента управления Substitution.

Примеры

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

<%@ 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#">  
  
  // The Substitution control calls this method to retrieve
  // the name of the current user from the HttpContext object. 
  // This section of the page is exempt from output caching. 
  public static string GetUser(HttpContext context)
  {
    return context.User.Identity.Name;
  }
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
  <title>Substitution.MethodName Property Example</title>
</head>
<body>
  <form id="Form1" runat="server">
  
    <h3>Substitution.MethodName Property Example</h3>  
    
    <!--This section of the page is not cached.-->
    Welcome to the site,
    <asp:substitution id="Substitution1"
      methodname="GetUser"
      runat="Server">
    </asp:substitution>
    
    <br /><br />
    
    <!--This section of the page is cached.-->
    Product list:
    <asp:bulletedlist id="ItemsBulletedList"             
      displaymode="Text" 
      runat="server">    
        <asp:ListItem>Product 1</asp:ListItem>
        <asp:ListItem>Product 2</asp:ListItem>
        <asp:ListItem>Product 3</asp:ListItem>
    </asp:bulletedlist>        

  </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">  
  
  ' The Substitution control calls this method to retrieve
  ' the name of the current user from the HttpContext object. 
  ' This section of the page is exempt from output caching. 
  Shared Function GetUser(ByVal context As HttpContext) As String
    Return context.User.Identity.Name
  End Function
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
  <title>Substitution.MethodName Property Example</title>
</head>
<body>
  <form id="Form1" runat="server">
  
    <h3>Substitution.MethodName Property Example</h3>  
    
    <!--This section of the page is not cached.-->
    Welcome to the site,
    <asp:substitution id="Substitution1"
      methodname="GetUser"
      runat="Server">
    </asp:substitution>
    
    <br /><br />
    
    <!--This section of the page is cached.-->
    Product list:
    <asp:bulletedlist id="ItemsBulletedList"             
      displaymode="Text" 
      runat="server">    
        <asp:ListItem>Product 1</asp:ListItem>
        <asp:ListItem>Product 2</asp:ListItem>
        <asp:ListItem>Product 3</asp:ListItem>
    </asp:bulletedlist>        

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

Комментарии

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

Параметр HttpContext инкапсулирует все сведения, относящиеся к HTTP, о отдельном HTTP-запросе. Его можно использовать для доступа к переменным сеанса, сведениям об авторизации и персонализации. Для получения дополнительной информации см. HttpResponseSubstitutionCallback.

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

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