HTTP RuntimeRequest Processing in an ASP.NET Application


HTTP Runtime ”Request Processing in an ASP.NET Application

As mentioned at the beginning of this chapter, ASP.NET is a complete Web application development platform. It is complete in the sense that it contains all the pieces and layers necessary to handle incoming requests and to create an output response in a Web application or XML Web service. The ASP.NET run ­time can be hosted in a custom application outside the Internet Information Services (IIS) Web server. However, both the diagram and the description that follow are based on the most common ASP.NET usage scenario: ASP.NET hosted in IIS.

Figure 1-2 illustrates a single incoming request into an ASP.NET Web application and the associated response that is generated by the components that participate in the request-processing life cycle.

At its core , the HTTP runtime handles an incoming Web request from a client application such as a Web browser, routes the request through the appropriate components in the application that process it, and then generates a response that is returned to the client application issuing the request.

An incoming HTTP Web request is first received by the IIS Web server, which hands this request to the ASP.NET ISAPI based on the extensions that ASP.NET is registered to handle. Some of the common file extensions handled by ASP.NET include .aspx, .asmx, and .ashx. The ASP.NET HTTP runtime serves as a bridge between IIS and the managed Web application.

The ASP.NET HTTP runtime initializes a number of objects to process the request. The HTTP runtime first creates an instance of the HttpContext object, which contains information about the request that is currently being processed , and it then makes that context object available to all other components involved in the processing logic. This context object flows through the linear processing chain shown in Figure 1-2, in which each object can add other data or objects as context information.

The HttpContext instance provides access to the request object, which is an instance of the HttpRequest class, and to the response object, which is an instance of the HttpResponse class. The request object represents the data being sent to the Web server by the requesting application and contains information such as the requested URL, any posted data, and HTTP headers. The response object contains the output content (such as the HTML stream) being sent back to the requesting application from the Web server. It allows the components involved in processing the request to generate content into the output stream and to add information about the type of the content, such as its MIME type. The HttpContext object also provides access to various services that are available for the duration of the request processing. These services include application and session state, the ASP.NET cache, and information about the user identity.

Figure 1-2. Request processing inside an ASP.NET Web application

graphics/f01hn02.jpg

The HTTP runtime assembles a processing pipeline composed of components referred to as HTTP modules to perform request preprocessing actions (such as cache lookup and authorization) and postprocessing actions (such as updating the cache). These components implement the IHttpModule interface. Each module in the pipeline handles various global application-level and request-specific events to perform its logic. These events include application start and end notifications, request start and end notifications, and various hooks into the life cycle of a request, such as authentication and authorization. Each module can also raise its own set of events that an application developer can handle.

The HTTP runtime also selects a single HTTP handler or HTTP handler factory that will be invoked to perform the actual processing of the incoming request, based on the request URL. An HTTP handler is a component that implements the IHttpHandler interface, while an HTTP handler factory is a component that implements the IHttpHandlerFactory interface. ASP.NET provides a number of built-in HTTP handler implementations to handle file extensions such as .aspx, .asmx, and .ashx. A handler uses the HttpContext object to gather information about the request and to write out the resulting response. ASP.NET does not impose arbitrary limitations on the implementation of an HTTP handler. A handler can use any of the information it is handed ”such as the request URL, request headers, and posted data ”and it can generate any form of output, either textual or binary.

One of the most commonly used HTTP handlers is the page handler. Each .aspx page in a Web application is an HTTP handler that handles incoming requests for that particular page. The implementation of this HTTP handler instantiates a hierarchy of server objects and user interface components named server controls that derive directly or indirectly from the System.Web.UI.Control class corresponding to the declarative content present in the .aspx file, and assembles them into a control tree. The control tree has its own life cycle. Essentially, the control tree inside each page handler processes a request and forms the response by rendering itself into some form of markup (typically HTML) that forms the response content. Chapter 2 provides a more detailed overview of how a page processes a request.



Developing Microsoft ASP. NET Server Controls and Components
Developing Microsoft ASP.NET Server Controls and Components (Pro-Developer)
ISBN: 0735615829
EAN: 2147483647
Year: 2005
Pages: 183

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net