Saturday, August 28, 2010

HttpModule



Http Handler

Http Modules

1.      Where will you use HttpHandlers ?
*Suppose I want
to create RSS feeds for my web site. I will create a handler which will emit
RSS formatted XML, rather than HTML
*Image Server : For serving images of different sizes.

Where will you use HttpModules?
*I want to add custom security handling to my web pages.   (In fact, ASP.NET itself implements Forms
auth using  a module.
*Logging request, logging page visits.
* Adding same header or footer to web pages.

HttpHandlers used by  ASP.NET :
.aspx (asp. Net page)
.asmx
.ashx (generic handler for all web handlers
that do not have ui and include a @WebHandler directive)
Trace.axd

HttpModules used by ASP.NET
*forms authentication

*caching *

session state

*client script services

HttpHandlers are invoked  only when  particular resource  is requested, which is assigned to the
handler.

Modules are invoked for each request







In a module's Init method, you can subscribe to various application events such as BeginRequest or EndRequestby binding the events to methods in the module





You
should use a module whenever you must create code that depends on application
events, and when the following conditions are true:


·        You want to re-use the module in other applications.


·        You want to avoid putting complex code in the Global.asax
file.


·        The module applies to all requests in the pipeline (IIS
7.0 Integrated mode only).


You should add code in the Global.asax
file whenever you must create code that depends on application events and you
do not have to reuse it across applications. You can also use the Global.asax file when you have to subscribe to events that
are not available to modules, such as
Session_Start and Session_End




The advantage of using the Global.asax file is that you can handle other registered
events such as Session_Start
and Session_End. In
addition, the Global.asax file enables you to
instantiate global objects that are available throughout the application.





Page_PreInit method cannot be bound using Global.asax,
it doesn’t work.








In IIS 7.0, the integrated
pipeline enables managed modules to subscribe to pipeline notifications for all
requests, not just requests for ASP.NET resources. Event handlers in the Global.asax file are invoked only for notifications during
requests for resources in the application. Custom modules in Integrated
mode can be explicitly scoped to receive event notifications only for
requests to the application. Otherwise, custom modules receive event
notification for all requests to the application. If the
precondition attribute of the add element of the modules section
is set to "managedHandler", the module is
scoped to the application.




No comments:

Post a Comment