What is ASP.NET’s Httphandler and Httpmodule?

Asked

Viewed 1,042 times

3

What is the Httphandler and Httpmodule of ASP.NET?

  1. How they work?
  2. And how to use?

1 answer

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:

  1. Implement Ihttphandler interface.
  2. Insert the handler into web.config or machine.config file.

  3. 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:

  1. Implementing the Ihttpmodule interface

  2. 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.

SOURCE

Browser other questions tagged

You are not signed in. Login or sign up in order to post.