Every .NET developer has hear about Handler but do you know the main purpose of handlers why do we need to use them ? Why do we not replace them with normal ASPX form ?
In simple one line answer i would like to say ASPX pages are good to use when you have some controls on pages ( dynamic HTML controls ) but suppose if there is a requirement of display dynamic images , views then it would be critical for web pages. In that scenario we use handlers for critical web pages.
There are two most important thing about Handlers that is :
First and foremost, HttpHandlers are far more reusable/portable than pages. Since there’s no visual element to an HttpHandler , they can easily be placed into their own assembly and reused from project to project or even sold as is. Secondly, the Page handler is relatively expensive. Going with the “Hello World” examples, if you do that in a page you’ll end up raising a number of events (onInit, onLoad, onPreRender, onUnload, …) and make use of a number of ASP.NET features such as viewstate and postback. In most cases, the performance hit is negligible, but it nonetheless highlights that you’re using the page framework when you have no need to.
In simple one line answer i would like to say ASPX pages are good to use when you have some controls on pages ( dynamic HTML controls ) but suppose if there is a requirement of display dynamic images , views then it would be critical for web pages. In that scenario we use handlers for critical web pages.
There are two most important thing about Handlers that is :
First and foremost, HttpHandlers are far more reusable/portable than pages. Since there’s no visual element to an HttpHandler , they can easily be placed into their own assembly and reused from project to project or even sold as is. Secondly, the Page handler is relatively expensive. Going with the “Hello World” examples, if you do that in a page you’ll end up raising a number of events (onInit, onLoad, onPreRender, onUnload, …) and make use of a number of ASP.NET features such as viewstate and postback. In most cases, the performance hit is negligible, but it nonetheless highlights that you’re using the page framework when you have no need to.
Why not to use HttpHandlers
The biggest and very significant drawback of HttpHandlers is that they can only be used for extensions that are mapped to ASP.NET in IIS. It might be great to create a file download counter for your .zip files using an HttpHandler, but since IIS doesn’t go through ASP.NET to serve .zip files, it isn’t going to work. One solution is to map those extra extension to ASP.NET, but that might have undesirable side effects and might not even be possible for you (many developers don’t have direct access to IIS). In this case, the only solution is to create an ISAPI filter which is much more difficult. IIS 7 promises to let us write ISAPI filters in .NET (or extend HttpHandlers beyond the ASP.NET pipeline depending on how you look at it), but that’s still a ways away.
No comments:
Post a Comment