Substitution.MethodName Propiedad

Definición

Obtiene o establece el nombre del método de devolución que se invoca cuando el control Substitution se ejecuta.

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

Valor de propiedad

String

Cadena que representa el nombre del método que se va a invocar cuando el control Substitution se ejecuta.

Ejemplos

En el ejemplo de código siguiente se muestra cómo agregar un Substitution control mediante declaración a una página web almacenada en caché de salida. Cuando se carga la página, se muestra una lista con viñetas estática al usuario. Esta sección de la página se almacena en caché y se actualiza solo cada 60 segundos. Cuando se ejecuta el Substitution control, llama al GetUser método , que devuelve una cadena que representa al usuario actual. Esta cadena se muestra en la ubicación del Substitution control en la página. Esta sección de la página no se almacena en caché y se actualiza cada vez que se actualiza la página.

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

Comentarios

Utilice 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 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. La cadena que devuelve el método de devolución de llamada es el contenido que se va a mostrar en la página en la ubicación del Substitution control.

El HttpContext parámetro encapsula toda la información específica de HTTP sobre una solicitud HTTP individual. Puede usarlo para acceder a variables de sesión, información de autorización y detalles de personalización. Para obtener más información, vea HttpResponseSubstitutionCallback.

Se aplica a

Consulte también