HTTP module is a .NET Framework class that implements the IHttpModule interface, they called as ISAPI filter in IIS stack so modules are counterpart in ASP.NET, have ability to intercept and handle system events and other modules events. Based on the web.config file, per application basis, HTTP modules can filter the raw data, the context, within the request. Note: all ASP.NET applications inherit a gang of system modules by default as configured in the global web.config Before we get in to the details of internals let us understand IHttpModule interface and HTTPApplication or ASP.NET Application object first. ASP.NET Application object (HTTPApplication)In classic pipeline mode an ASP.NET request is handed over to an ISAPI extension right after IIS has obtained an authentication token for the sender. An ISAPI extension, HTTP Handler is ASP.NET counterpart, is a Win32 DLL that gets loaded into the IIS worker process that's in charge for any given Web application. The ISAPI extension will load the CLR in the worker process and launch the ASP.NET runtime pipeline to actually process the request. In the ASP.NET pipeline, the request life cycle is governed by a static instance of the HttpRuntime class. A single instance of the HttpRuntime class exists per application, and it's created when the first request for the application comes in. When the HttpRuntime object is takes over the control to process a request, it performs a number of initialization tasks the first one is the creation of the HTTP context object (which contains the ASP.NET intrinsic objects like Response, Request, Session and many more) and followed by creation of an ASP.NET application object to carry out the request. So by now we have Worker Process, CRL up and running, HttpRuntime object, HttpContext object, HttpApplication object. ASP.NET application object uses newly created HttpContext object to complete the request. Now given ASP.NET application object let us see where and all and what and all we can do. Don't forget "many more" we will see them. They are the concern of this topic. Before that, let us see what IHttpModule is first.IHttpModule interfacepublic interface IHttpModule
{
void Dispose();
void Init(HttpApplication context);
}The IHttpModule interface has two methods namely Init and Dispose. Any class that inherits from IHttpModule needs to provide the implementation for these methods. As we all know that Dispose method takes care of resource cleanup typically closing DB connection, any handlers to the costly disk resources. We have lest concern about this method. Let us see what can, or have to, do with the Init method. Init method, has one parameter that is HttpApplication Object, at first initializes the http module and prepares for handling requests. It receives the HttpApplication object reference when it executes. As said now http module has the access to all intrinsic objects and many more. Read more: C# Corner
{
void Dispose();
void Init(HttpApplication context);
}The IHttpModule interface has two methods namely Init and Dispose. Any class that inherits from IHttpModule needs to provide the implementation for these methods. As we all know that Dispose method takes care of resource cleanup typically closing DB connection, any handlers to the costly disk resources. We have lest concern about this method. Let us see what can, or have to, do with the Init method. Init method, has one parameter that is HttpApplication Object, at first initializes the http module and prepares for handling requests. It receives the HttpApplication object reference when it executes. As said now http module has the access to all intrinsic objects and many more. Read more: C# Corner
0 comments:
Post a Comment