Reputation: 28672
As i know that asp.net fulfill all the requirements for any web application but what are the ground rules for creating custom httphandler and httpmodule in asp.net.
Edit:For example I want to fetch image from database then what i should i use httphandler or normally read image from database.If httphandler then why?
Upvotes: 0
Views: 3339
Reputation: 1
.aspx
page)Upvotes: 0
Reputation: 8759
First off, keep in mind that an ASP.NET page is an HTTP Handler, just one that's more feature-rich. (The System.Web.UI.Page
class implements IHttpHandler
.)
As Chris Lively noted, a generic HTTP Handler - that is a class you create that implements IHttpHandler
- is going to be simpler and more efficient than using a standard ASP.NET page because it doesn't go through the entire page lifecycle, allows you to focus on just crafting the output in the ProcessRequest
method, and so on.
But if the task at hand is specifically to display an image from a database, rather than writing your own HTTP Handler consider using the GeneratedImage control from Microsoft.
In a nutshell, the GeneratedImage control is an HTTP Handler base class created by Microsoft that is designed to display database images. It's easy to use, supports caching and a host of other features. Why reinvent the wheel?
For more information on using this, see: Dynamically Generating and Caching Images in ASP.NET with the GeneratedImage Control. Here's the article's synopsis:
The GeneratedImage control is a combination of an ASP.NET Web Control and a set of classes that facilitate programmatically creating, serving, caching, and transforming images. If you store images in the database that need to be served from a web page, if you need to create images on the fly, or if you need to resize, add watermarks, or perform some other image transform, then the GeneratedImage control can help.
Happy Programming!
Upvotes: 1
Reputation: 91
HTTPHandlers to handle the request. But HTTPModules are to access the life-cycle events on the request. You can have only one HTTPHandler but can plug in more than one HTTPModules to examine and handle the requests.
Upvotes: 4
Reputation: 6916
As a thumb rule HttpHandlers
are when you need to serve something to the browser, a page, image or some concrete resource. While HttpModules
are for responding to events in the pipeline happening on the server. Ie handling errors, rewriting the url, logging stuff, checking for login-cookie, filtering the input or output stream etc. etc.
Upvotes: 1
Reputation: 88072
Okay, now that we know you want to pull an image from a database.
Yes, using a Generic Handler (.ashx) is the best way to do this.
It's as simply as saying Add | New Item and picking Generic Handler from the list.
Generic handlers do not have the full page life cycle which makes them both faster and easier to deal with. You just need to provide some code in the ProcessRequest method to pull the image out of the database and response.binarywrite it to the browser.
Upvotes: 1