HttpResponseBase.AddOnSendingHeaders(Action<HttpContextBase>) 方法
定义
注册一个回调,在即将为此请求发送响应标头之前,ASP.NET 运行时将会调用此回调。Registers a callback that the ASP.NET runtime will invoke immediately before response headers are sent for this request.
public:
virtual System::Web::ISubscriptionToken ^ AddOnSendingHeaders(Action<System::Web::HttpContextBase ^> ^ callback);
public virtual System.Web.ISubscriptionToken AddOnSendingHeaders (Action<System.Web.HttpContextBase> callback);
abstract member AddOnSendingHeaders : Action<System.Web.HttpContextBase> -> System.Web.ISubscriptionToken
override this.AddOnSendingHeaders : Action<System.Web.HttpContextBase> -> System.Web.ISubscriptionToken
Public Overridable Function AddOnSendingHeaders (callback As Action(Of HttpContextBase)) As ISubscriptionToken
参数
- callback
- Action<HttpContextBase>
回调方法。The callback method.
返回
返回一个 ISubscriptionToken 对象,它表示对 OnSendingHeaders 伪事件的订阅。Returns an ISubscriptionToken object that represents the subscription to the OnSendingHeaders pseudo event.
注解
伪事件对 onsendingheaders 与 IHttpModule 管道事件的不同之处在于,它是一个每个请求订阅,而不是按应用程序订阅。The pseudo event OnSendingHeaders differs from the IHttpModule-level pipeline event in that it is a per-request subscription rather than a per-application subscription. 目的是回调可以修改响应状态代码,也可以设置响应 cookie 或标头。The intent is that the callback may modify the response status code or may set a response cookie or header. 其他使用注意事项和注意事项:Other usage notes and caveats:
此方法仅在以下情况下有效: IIS 在集成管道模式管道中运行,并且仅在当前请求尚未发送响应标头时有效。This method is effective only when IIS runs in integrated pipeline mode pipeline and only if response headers haven't yet been sent for the current request.
ASP.NET 运行时不保证调用回调的线程的任何内容。The ASP.NET runtime does not guarantee anything about the thread that the callback is invoked on. 例如,如果正在执行后台刷新,则可在后台线程中同步调用回调。For example, the callback may be invoked synchronously in a background thread if a background flush is being performed. Current 不保证在此类线程中可用。Current is not guaranteed to be available in such a thread.
回调不得调用任何操作响应实体正文或导致刷新的方法。The callback must not call any method that manipulates the response entity body or that results in a flush. 例如,回调不得调用 Redirect ,因为该方法可以操作响应实体正文。For example, the callback must not call Redirect, as that method may manipulate the response entity body.
回调必须只包含短时间运行的同步代码。The callback must contain only short-running synchronous code. 尝试调用异步操作或等待这样的操作可能会导致死锁。Attempting to invoke an asynchronous operation or wait on such an operation could result in a deadlock.
回调不得引发异常;否则,行为是不确定的。The callback must not throw an exception; otherwise behavior is undefined.