What is HTTP module and HTTP handler in ASP.NET?
HTTP Handler:
It is a type that runs in response to a request made to an ASP.NET application. A request can be for any type of ASP.NET resource but it is the HTTPHandler that generates the response. HTTP Handler is used to mapping incoming requests to the appropriate IHttpHandler
or IhttpHandlerFactory
class.This is done based on the URL requested and the verb used to request it. One of the most common handlers is the page handler that runs in response to a request made for an .aspx
page.
Another handler is a web service handler that runs in response to a request for a .asmx
web service. Generic web handler (.ashx
) is the default web handler and it is usually used when we create a custom web handler.
Example:
<configuration> <system.web> <httpHandlers> <add verb="*" path="*.tmp" type="System.Web.HttpForbiddenHandler, System.Web, Version=1.0.2411.0, Culture=neutral /> </httpHandlers> </system.web> </configuration>
HTTP Module:
It enables you to configure the HTTP modules used within your application.This tag supports the <add>
, <remove>
, and <clear>
subtags.The <add>
subtag specifies the HTTP module class to add to your application. It has two attributes, type and name.
Example:
<configuration> <system.web> <httpModules> <add name="OutputCache" type="System.Web.Caching.OutputCacheModule" /> <add name="Session" type="System.Web.SessionState.SessionStateModule" /> <add name="WindowsAuthentication" type="System.Web.Security.WindowsAuthenticationModule" /> </httpModules> </system.web> </configuration>