HttpResponse.WriteSubstitution(HttpResponseSubstitutionCallback) 方法

定義

允許回應替代區塊插入回應,以便為輸出快取的回應,動態產生指定的回應區域。Allows insertion of response substitution blocks into the response, which allows dynamic generation of specified response regions for output cached responses.

public:
 void WriteSubstitution(System::Web::HttpResponseSubstitutionCallback ^ callback);
public void WriteSubstitution (System.Web.HttpResponseSubstitutionCallback callback);
member this.WriteSubstitution : System.Web.HttpResponseSubstitutionCallback -> unit
Public Sub WriteSubstitution (callback As HttpResponseSubstitutionCallback)

參數

callback
HttpResponseSubstitutionCallback

要替代的方法、使用者控制項或物件。The method, user control, or object to substitute.

例外狀況

callback 參數之目標的型別為 ControlThe target of the callback parameter is of type Control.

備註

您可以在輸出WriteSubstitution快取的頁面中,使用方法來進行快取後的替代。You can use the WriteSubstitution method for post-cache substitution in your output-cached pages. 藉由將HttpContext物件傳遞至具有指定HttpResponseSubstitutionCallback簽章的回呼方法,您可以在頁面快取中的任何指定位置取代輸出快取的內容。By passing a HttpContext object to a callback method with a prescribed HttpResponseSubstitutionCallback signature, you can replace output cached content at any given location in the page cache. 若要起始取代,請呼叫WriteSubstitution方法,將回呼方法傳遞給它,它必須是安全線程,而且可以是下列其中一項:To initiate the replacement, call the WriteSubstitution method, passing it the callback method, which must be thread safe and can be either of the following:

  • 容器頁面或使用者控制項上的靜態方法。A static method on the container page or user control.

  • 另一個任意物件上的靜態或實例方法。A static or instance method on another arbitrary object.

第一次要求頁面時, WriteSubstitutionHttpResponseSubstitutionCallback呼叫委派來產生輸出。On the first request to the page, the WriteSubstitution calls the HttpResponseSubstitutionCallback delegate to produce the output. 然後,它會將替代緩衝區新增至回應,這會保留委派以在未來要求時呼叫。Then, it adds a substitution buffer to the response, which retains the delegate to call on future requests. 最後,它會降低從公用到僅限伺服器的用戶端快取性,確保未來對頁面提出的要求會透過不要在用戶端上快取來重新叫用委派。Finally, it degrades client-side cacheability from public to server-only, ensuring future requests to the page re-invoke the delegate by not caching on the client.

注意

在使用者控制項層級套用輸出快取的使用者控制項,不支援後置快取替代。Post-cache substitution is not supported for a cached user control where output caching is applied at the user control level. 這也稱為片段快取。This is also known as fragment caching. 如需詳細資訊,請參閱快取部分的 ASP.NET 網頁For more information, see Caching Portions of an ASP.NET Page.

適用於

另請參閱