Substitution.MethodName Proprietà

Definizione

Ottiene o imposta il nome del metodo di callback da richiamare quando viene eseguito il controllo 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

Valore della proprietà

String

Stringa che rappresenta il nome del metodo da richiamare quando viene eseguito il controllo Substitution.

Esempio

Nell'esempio di codice seguente viene illustrato come aggiungere un Substitution controllo in modo dichiarativo a una pagina Web memorizzata nella cache di output. Quando la pagina viene caricata, all'utente viene visualizzato un elenco puntato statico. Questa sezione della pagina viene memorizzata nella cache e aggiornata solo ogni 60 secondi. Quando il Substitution controllo viene eseguito, chiama il GetUser metodo , che restituisce una stringa che rappresenta l'utente corrente. Questa stringa viene visualizzata nella posizione del Substitution controllo nella pagina. Questa sezione della pagina non viene memorizzata nella cache e viene aggiornata ogni volta che la pagina viene aggiornata.

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

Commenti

Utilizzare la MethodName proprietà per specificare il nome del metodo di callback da richiamare quando viene eseguito il Substitution controllo. 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 di un HttpResponseSubstitutionCallback delegato che accetta un HttpContext parametro e restituisce una stringa. La stringa restituita dal metodo di callback è il contenuto da visualizzare nella pagina nella posizione del Substitution controllo.

Il HttpContext parametro incapsula tutte le informazioni specifiche di HTTP relative a una singola richiesta HTTP. È possibile usarlo per accedere a variabili di sessione, informazioni di autorizzazione e dettagli sulla personalizzazione. Per altre informazioni, vedere HttpResponseSubstitutionCallback.

Si applica a

Vedi anche