Thursday, August 18, 2016

HTTP Modules and HTTP Handler

Every user requests to the IIS web server through the HTTP Pipeline (HTTP modules and HTTP handlers) to process the request.

Inject the logic before page is requested. such as URL Rewrite, authentication.


Modules are called before and after the handler executes. Modules enable developers to intercept, participate in, or modify each individual request. Handlers are used to process individual endpoint requests. Handlers enable the ASP.NET Framework to process individual HTTP URLs or groups of URL extensions within an application. Unlike modules, only one handler is used to process a request”.

________________________________________________________________________

HTTP Modules

Process in every request to the application. Filter (examine) incoming request.
Inject functionality for all coming requests e.g. URL rewrite or security.
regardless extension and take action based on the request. 


Advantages Of Http Modules
  • HTTP modules can be added at the site, folder, or file level as opposed to ISAPI filters, which could only be added at the global or site level
  • Can be reuse across application.
Use For :
  • Custom headers and footers
  • Custom caching and session handling mechanism
  • Gater Statistics and logging for every page request
  • Converting http to https and vice versa
  • User authentication etc.
Why not Global.asax ?
  • HttpModule can add to the GAC, and reuse them across many applications.
  • However HTTPModule don't have such session_start event
________________________________________________________

HTTP Handlers
Handle specific request on the basis of the extensions(aspx), we can define our custom HttpHandler for specific extension. e.g. (.gid .jpeg) 
Response to a request made to an ASP.NET Web Application based on extension (.aspx or .GIF)


Why we need to create our own HTTP Handler?
Use HTTP handler for images, we can increase performance by quicker response time to just show low level interface (e.g. image only) to avoid ASP.NET full page processing model such as (web page object, persisting view state etc.)
  • When to use ?
    • Display Image
    • RSS-formatted XML.
    • Perform ad hoc database query.
    • Return some binary data.
  • Default Handlers
    • .aspx - Handles web pages
    • .ascx - Handles user control pages
    • .asmx - Handles web service pages
    • .axd - Handles trace functionality
  • Custom HTTP handler by implement IHttpHandler Interface to synchronous handler, IHttpAsyncHander to create asynchronous handler.
<add verb="*" path="*.jpg" type="SimpleHTTPHanlder.ImageHandler,SimpleHTTPHanlder"/>
verb : HTTP Post or HTTP GET request
type : Handler ClassName, assembly DLL

HTTP handler process, it will not process if not .jpg
e.g. www.penyu.aspx/image1.jpg  

No comments:

Post a Comment