1. HTTP requests are passed to an instance of the HttpRuntime class, which represents the beginning of the pipe. The HttpRuntime object examines the request and figures out which application it was sent to (from the pipeline's perspective, a virtual directory is an application).
2. Then it uses an HttpApplicationFactory to either find or create an HttpApplication object to process the request. An HttpApplication, its modules, and its handler will only be used to process one request at a time. If multiple requests targeting the same application arrive simultaneously, multiple HttpApplication objects will be used
3. An HttpApplication holds a collection of HTTP module objects, implementations of the IHttpModule interface. HTTP modules are filters that can examine and modify the contents of HTTP request and response messages as they pass through the pipeline.
4. The HttpApplication object uses an HTTP handler factory to either find or create an HTTP handler object. HTTP handlers are endpoints for HTTP communication that process request messages and generate corresponding response messages. HTTP handlers and handler factories implement the IHttpHandler and IHttpHandlerFactory interfaces, respectively.

HTTP Handlers
interface IHttpHandler { // called to process request and generate response void ProcessRequest(HttpContext ctx); // called to see if handler can be pooled bool IsReuseable { get; } }
The ProcessRequest method is called by an HttpApplication object when it wants the handler to process the current HTTP request and to generate a response. The IsReuseable property is accessed in order to determine whether a handler can be used more than once.
In addition to implementing custom handlers, you can also write your own handler factories. A handler factory is a simple class that implements the IHttpHandlerFactory interface. Handler factories are deployed the same way handlers are; the only difference is that the entry in the Web.config file refers the factory class instead of the handler class that the factory instantiates. If you implement a custom HTTP handler without implementing a handler factory, an instance of the pipeline-provided default factory class, HandlerFactoryWrapper, is used instead.
Standard Handlers
HTTP Modules
HTTP modules are filters that process HTTP request and response messages as they pass through the pipeline, examining and possibly modifying their content.
interface IHttpModule { // called to attach module to app events void Init(HttpApplication app); // called to clean up void Dispose() }
The Init method is called by an HttpApplication object when the module is first created. It gives the module the opportunity to attach one or
more event handlers to the events exposed by the HttpApplication object.
The Pipeline Event Model
If a module aborts normal message handling during an event handler by calling CompleteRequest, the ASP.NET HTTP pipeline interrupts processing after that event completes. However, EndRequest and the events that follow are still fired.
Application Object
ASP.NET HTTP pipeline treats each virtual directory as an application. When a request for a URL in a given virtual directory arrives, the HttpRuntime object that dispatches the message uses an HttpApplicationFactory object to find or create an HttpApplication object to process the request. A given HttpApplication object will only be used to service requests sent to a single virtual directory, and there can be multiple pooled instances of HttpApplication for the same virtual directory.
If you want, you can customize the behavior of the HttpApplication class for your application (virtual directory). You do this by writing a global.asax file. If the HTTP pipeline detects a global.asax file in your virtual directory, it compiles it into an HttpApplication-derived class. Then it instantiates your specialized HttpApplication subclass and uses it to service requests.
There are three categories of events handled by the Application object
1. Events fired by HTTP Pipeline i.e. fired by the Application class itself
2. Application-level events i.e. Application_OnStart and Application_OnEnd.
3. Events fired by HTTP Modules
http://msdn.microsoft.com/en-us/magazine/cc188942.aspx
http://stackoverflow.com/questions/1739164/http-handlers-when-to-use-synchronous-asynchronous-generic-handlers-ashx
No comments:
Post a Comment