Online Book Reader

Home Category

Programming Microsoft ASP.NET 4 - Dino Esposito [332]

By Root 5405 0
is invoked to produce an identity for the unauthenticated user. This is done for the sake of consistency so that code doesn’t need to worry about null identities.

PostAuthenticateRequest The request has been authenticated. All the information available is stored in the HttpContext’s User property.

AuthorizeRequest The request authorization is about to occur. This event is commonly handled by application code to do custom authorization based on business logic or other application requirements.

PostAuthorizeRequest The request has been authorized.

ResolveRequestCache The ASP.NET runtime verifies whether returning a previously cached page can resolve the request. If a valid cached representation is found, the request is served from the cache and the request is short-circuited, calling only any registered EndRequest handlers.

PostResolveRequestCache The request can’t be served from the cache, and the procedure continues. An HTTP handler corresponding to the requested URL is created at this point. If the requested resource is an .aspx page, an instance of a page class is created.

MapRequestHandler The event is fired to determine the request handler.

PostMapRequestHandler The event fires when the HTTP handler corresponding to the requested URL has been successfully created.

AcquireRequestState The module that hooks up this event is willing to retrieve any state information for the request. A number of factors are relevant here: the handler must support session state in some form, and there must be a valid session ID.

PostAcquireRequestState The state information (such as Application, Session) has been acquired.

PreRequestHandlerExecute This event is fired immediately prior to executing the handler for a given request. The handler does its job and generates the output for the client.

ExecuteRequestHandler The handler does its job and processes the request.

PostRequestHandlerExecute This event is raised when the handler has generated the response text.

ReleaseRequestState This event is raised when the handler releases its state information and prepares to shut down. This event is used by the session state module to update the dirty session state if necessary.

PostReleaseRequestState The state, as modified by the page execution, has been persisted. Any relevant response filtering is done at this point. (I’ll say more about this topic later.)

UpdateRequestCache The ASP.NET runtime determines whether the generated output, now also properly filtered by registered modules, should be cached to be reused with upcoming identical requests.

PostUpdateRequestCache The page has been saved to the output cache if it was configured to do so.

LogRequest The event indicates that the runtime is ready to log the results of the request. Logging is guaranteed to execute even if errors occur.

PostLogRequest The request has been logged.

EndRequest This event fires as the final step of the HTTP pipeline. Control passes back to the HttpRuntime object, which is responsible for the actual forwarding of the response to the client. At this point, the text has not been sent yet.

If an unhandled error occurs at any point during the processing, it is treated using the code (if any) associated with the Error event. As mentioned, events can be handled in HTTP modules as well as in global.asax.

Note

The Error event provides a centralized console for capturing any unhandled exception in order to recover gracefully or just to capture the state of the application and log it. By writing an HTTP module that just intercepts the Error event, you have a simple but terribly effective and reusable mechanism for error handling and logging. At the end of the day, this is the core of the engine of popular tools for ASP.NET error handling, logging, and reporting—ELMAH.

The global.asax File


The global.asax file is used by Web applications to handle some application-level events raised by the ASP.NET runtime or by registered HTTP modules. The global.asax file is optional.

Return Main Page Previous Page Next Page

®Online Book Reader