The attached sample illustrates how to execute true server-side child requests that go though the entire HTTP pipeline in ASP.NET v2.0.  The full source code is included.

Out of the box ASP.NET supports two similar features:

  • Server.Execute. This method executes (calls ProcessRequest method on) the HTTP handler corresponding to the given path.  None of the pipeline events (for HTTP Modules or GLOBAL.ASAX) are fired and thus, for example, authentication rules are by-passed.
  • Response.Redirect. This method does re-enter the pipeline for the 'child request', but at a cost of the roundtrip to the client that issued the original request.

Child Request feature sample allows spawning of server-side requests that go through the entire HTTP pipeline and capturing of the responses.  Several child requests could be used in the context of one parent request. In fact, no parent request is needed at all (which is yet another advantage over Server.Execute and Response.Redirect).

Child Request API

The API is quite simple to use:

  1. Create an instance of ChildRequest class
  2. Call ChildRequestExecutor.ExecuteChildRequest to execute the child request synchronously (BeginExecuteChildRequest and EndExecuteChildRequest for asynchronous child request execution)
  3. Obtain the response from ChildRequest properties (Status, Headers, Content).

In addition, the instance of the ChildRequest being executed can be retrieved from a module or a handler using ChildRequestExecutor.GetChildRequestFromContext. This can be useful in order to retrieve UserData property of ChildRequest set by the caller.

HTTP Pipeline in ASP.NET 2.0

Related to this feature, here is a quick reference for the steps in HTTP pipeline in ASP.NET 2.0.  Some of the steps are internal (cannot be subscribed by HTTP modules or GLOBAL.ASAX):

  1. Internal step to validate request.  Protects against malicious attacks exploiting path canonicalization
  2. Internal step to perform URL mapping (if the URL mapping feature is enabled)
  3. Fire BeginRequest event
  4. Fire AuthenticateRequest event
  5. Fire DefaultAuthentication internal event
  6. Fire PostAuthenticateRequest event
  7. Fire AuthorizeRequest event
  8. Fire PostAuthorizeRequest event
  9. Fire ResolveRequestCache event
  10. Fire PostResolveRequestCache event
  11. Internal step to determine the IHttpHandler to process the current request (this is when the page compilation takes place)
  12. Fire PostMapRequestHandler event
  13. Fire AcquireRequestState event
  14. Fire PostAcquireRequestState event
  15. Fire PreRequestHandlerExecute event
  16. Internal step to execute the IHttpHandler (call its ProcessRequest method) for the current request. The handler is determined at step #11
  17. Fire PostRequestHandlerExecute event
  18. Fire ReleaseRequestState event
  19. Fire PostReleaseRequestState event
  20. Internal step to perform response filtering (only if HttpResponse.Filter is installed)
  21. Fire UpdateRequestCache event
  22. Fire PostUpdateRequestCache event
  23. Fire EndRequest event.  This is the only event that is guaranteed to be fired for each request