HttpResponse.WriteSubstitution(HttpResponseSubstitutionCallback) HttpResponse.WriteSubstitution(HttpResponseSubstitutionCallback) HttpResponse.WriteSubstitution(HttpResponseSubstitutionCallback) HttpResponse.WriteSubstitution(HttpResponseSubstitutionCallback) Method

定义

允许将响应替换块插入响应,从而允许为缓存的输出响应动态生成指定的响应区域。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 HttpResponseSubstitutionCallback HttpResponseSubstitutionCallback HttpResponseSubstitutionCallback

要替换的方法、用户控件或对象。The method, user control, or object to substitute.

异常

callback 参数的目标的为 Control 类型。The 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.

在第一次请求页面时,将WriteSubstitution HttpResponseSubstitutionCallback调用委托以生成输出。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.

适用于

另请参阅