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

キャッシュ後置換が必要なコントロールを持つページの HTTP 要求情報が格納された HttpContext

戻り値

クライアントへの送信前に、キャッシュされた応答に挿入されたコンテンツ。

次のコード例は、出力キャッシュされた Web ページにプログラムによってコントロールを追加 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組み合わせて、 コントロールと AdRotator コントロールのキャッシュ後コンテンツをSubstitutionレンダリングするために使用されます。

コントロールの場合は Substitution 、 プロパティを MethodName 使用して、コントロールの実行時に呼び出すコールバック メソッドの名前を Substitution 指定します。 指定するコールバック メソッドは、ページまたはコントロールを含む Substitution ユーザー コントロールの静的メソッドである必要があります。 コールバック メソッドのシグネチャは、パラメーターを受け取りHttpContext、文字列をHttpResponseSubstitutionCallback返すデリゲートのシグネチャと一致する必要があります。

コントロールの AdRotator 場合、イベントに対してイベント ハンドラーが指定されていない限り、レンダリングはページ キャッシュに AdCreated 依存しません。 イベント ハンドラーが存在しない AdCreated 場合は、キャッシュ後の置換を使用してコンテンツを AdRotator レンダリングします。

拡張メソッド

GetMethodInfo(Delegate)

指定したデリゲートによって表されるメソッドを表すオブジェクトを取得します。

適用対象

こちらもご覧ください