What is the HttpHandler and HttpModule of ASP.NET?

3

What is the HttpHandler and HttpModule of ASP.NET?

  • How do they work?
  • How to use?
  • asked by anonymous 26.01.2017 / 16:26

    1 answer

    5

    In short:

    HttpHandler is where the request is directed.

    HttpModule is a station along the way.

    For me the best answer from the source below!

    The main and common goal of HttpHandler and HttpModule is to inject pre-processing logic before the ASP.NET request arrives at the IIS server.

    ASP.NET provides two ways to inject logic into the request pipeline;

    HttpHandlers helps us inject preprocessor 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 .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 your site that ends in .rss, ASP.NET calls your handler to process the request.

    There are three steps involved in creating the Handler:

  • Implement IHttpHandler interface.
  • Insert the handler in the     file web.config or machine.config.

  • Map the extension of     (* .arshad) file for aspnet_isapi.dll in IIS.

  • IHttpHandler interface has ProcessRequest method and IsReusable property that needs to be implemented. ProcessRequest : You must write the code that outputs to the handler. IsResuable : This property informs if this handler can be reused or not.

    Registering the handler in the web.config file:

    <httpHandlers>
       <add verb="*" path="*.arshad" type="namespace.classname, assemblyname" />
    </httpHandlers>
    

    Note : Here we are dealing with any filename with arshad extension.

    HttpModule is an event-based processor for injecting preprocessing logic before the request reaches the IIS server. ASP.NET uses HttpModule to implement bundles of its own functionality, such as authentication and authorization, session management and output caching, and so on. ASP.NET engine issues many events such as passing the request 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 IIS.

    There are two steps involved in creating modules, they are:

  • Implement the IHttpModule interface

  • Register module in 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

        
    26.01.2017 / 16:51