Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

httpmodules httphandlers, whats the ideal use of them? when to use and when not to use?

Tags:

asp.net

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?

like image 743
Amr Elgarhy Avatar asked Aug 16 '09 20:08

Amr Elgarhy


3 Answers

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.

like image 119
Manu Avatar answered Nov 19 '22 16:11

Manu


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).

like image 43
AnthonyWJones Avatar answered Nov 19 '22 16:11

AnthonyWJones


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.

like image 3
chrissr Avatar answered Nov 19 '22 14:11

chrissr