Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

HttpResponse::AddOnSendingHeaders Method (Action<HttpContext^>^)

.NET Framework (current version)
 

[Supported in the .NET Framework 4.5.2 and later versions]

Registers a callback that the ASP.NET runtime will invoke immediately before response headers are sent for this request.

Namespace:   System.Web
Assembly:  System.Web (in System.Web.dll)

public:
ISubscriptionToken^ AddOnSendingHeaders(
	Action<HttpContext^>^ callback
)

Parameters

callback
Type: System::Action<HttpContext^>^

The callback method.

Return Value

Type: System.Web::ISubscriptionToken^

An ISubscriptionToken object that represents the subscription to the OnSendingHeaders pseudo-event.

System_CAPS_importantImportant

The AddOnSendingHeaders method is not invoked if the native module flushes the response first.

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. 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:

  • 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.

  • 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 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. 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.

.NET Framework
Available since 4.5.2
Return to top
Show:
© 2017 Microsoft