Share via


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 コントロールの実行時に呼び出すメソッドの名前を表す文字列。

次のコード例は、出力キャッシュされた Web ページに宣言によってコントロールを追加 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 ページコントロールまたはユーザー コントロール上の静的メソッドである必要があります。 コールバック メソッドのシグネチャは、パラメーターを受け取ってHttpContext文字列を返すデリゲートのシグネチャHttpResponseSubstitutionCallbackと一致する必要があります。 コールバック メソッドが返す文字列は、コントロールの場所にあるページに表示する Substitution 内容です。

このパラメーターは HttpContext 、個々の HTTP 要求に関するすべての HTTP 固有の情報をカプセル化します。 これを使用して、セッション変数、認証情報、およびパーソナル化の詳細にアクセスできます。 詳細については、「HttpResponseSubstitutionCallback」を参照してください。

適用対象

こちらもご覧ください