3
What is the Httphandler and Httpmodule of ASP.NET?
- How they work?
- And how to use?
3
What is the Httphandler and Httpmodule of ASP.NET?
6
In short:
Httphandler is where the request is addressed.
Httpmodule is a station along the way.
For me better answer taken from the source below!
The main and common objective of Httphandler and Httpmodule is to inject preprocessing logic before the ASP.NET request reaches the IIS server.
ASP.NET provides two ways to inject logic into the request pipeline;
Httphandlers helps us inject preprocessing logic based on the extension of the requested file name. ASP.NET uses HTTP handlers to implement a lot of its own functionality. For example, ASP.NET uses handlers to process files .aspx, .asmx e trace.axd.
Example: feeds RSS
: To create an RSS feed for a web site, you can create a handler that emits XML formatted in RSS. Therefore, when users submit a request to their site ending in . rss, ASP.NET calls its handler to process the request.
There are three steps involved in creating the Handler:
Insert the handler into web.config or machine.config file.
Map the extension of file (* .Arshad) for aspnet_isapi.dll on IIS.
IHttpHandler
interface has ProcessRequest
method and IsReusable
property that needs to be implemented. ProcessRequest
: You must write the code that produces the output to the handler. IsResuable
: This property informs whether this handler can be reused or not.
Registering the handler in the file web.config
:
<httpHandlers>
<add verb="*" path="*.arshad" type="namespace.classname, assemblyname" />
</httpHandlers>
Note: here we are dealing with any file name with extension Arshad.
Httpmodule is an event-based processor to inject preprocessing logic before the order reaches the IIS server. ASP.NET uses Httpmodule to implement batches of its own functionality, such as authentication and authorization, session management and output cache, etc. ASP.NET engine emits many events such as order passing through the request pipeline. Some of these events are Authenticaterequest, Authorizerequest, Beginrequest, Endrequest. Using Httpmodule you can write logic in these events. These logics are executed as events are triggered and before the request reaches the OSI.
There are two stages involved in the creation of modules, are they:
Implementing the Ihttpmodule interface
Register the module in the web.config or machine.config file
Example: Security: Using the HTTP module, you can perform custom authentication or other security checks before the request reaches IIS.
Browser other questions tagged c# asp.net
You are not signed in. Login or sign up in order to post.