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

戻り値

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

次のコード例では、 Substitution コントロールをプログラムで出力キャッシュ Web ページに追加する方法を示します。 ページが読み込まれると、現在の日付と時刻がラベルでユーザーに表示されます。 ページのこのセクションはキャッシュされ、60 秒ごとに更新されます。 Substitution コントロールは、GetCurrentDateTime デリゲートのシグネチャと一致する必要があるHttpResponseSubstitutionCallback メソッドを呼び出します。 GetCurrentDateTime メソッドによって返される文字列がユーザーに表示されます。 ページのこのセクションはキャッシュされず、ページが更新されるたびに更新されます。 MethodName コントロールの 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#">  
  
  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 メソッドと組み合わせて、SubstitutionコントロールとAdRotator コントロールのキャッシュ後コンテンツをレンダリングするために使用されます。

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

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

拡張メソッド

名前 説明
GetMethodInfo(Delegate)

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

適用対象

こちらもご覧ください