I have some questions about httpmodules and httphandlers, i am a little confused of the real need of them, i created many websites, but rarely used them, sure i lost a benefit from not using them, what are these benefits?
When to use and when not to use?
you could use httpmodules for authentication, auditing or url-rewriting. Since every request first passes through all modules, before it's handled by the httphandler, this is the place to apply code that you want to run before your specific application code.
You would use an httphandler if you don't want to rely on the asp.net engine. for example you could write your own rendering mechanism based on AJAX, XML and XSLT which does not rely on traditional asp.net pages.
Have you found yourself writing code in an ASPX Page_Load event to emit something to the response and then calling Response.End? That was likely best written as a HttpHandler (ashx).
HttpModules and HttpHandlers are useful when you wish to change IIS's default handling of documents either by changing the behavior entirely or adding pre or post processing to the document.
One practical application I've had for an HttpModule is for dynamic thumbnail creation. I wrote an HttpModule that handled all image requests. If the request contained the query string "?thumb", I'd dynamically generate a thumbnail rather than serving up the original image.
I've also seen HttpModules used to remove comments and whitespace from aspx page output and url rewriting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With