Displaying Images in ASP.NET Using HttpHandlers
page 4 of 8
by Electronic Screw
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 30087/ 338

Creating an HttpHandler

To create an HttpHandler, we need to implement the IHttpHandler interface. The IHttpHandler contains one property and one method.

Listing 1 - IHttpHandler interface

public interface IHttpHandler 
 {
   bool IsReusable { get; } 
   void ProcessRequest(HttpContext context); 
 }

The property IsReusable specifies whether the ASP.NET should reuse the same instance of the HttpHandler for multiple requests.

The ProcessRequest () method is where you actually implement the logic to handle the request.

After you create the HttpHandler, you have to map a path to the handler in the web.config.

A typical web.config configuration for the handler looks like the following.

Listing 2 - web.config setting for httpHandler

<configuration>
   <system.web>
     ...
     <httpHandlers>
      <add verb="*" path="getAvatarImage.img" type="Sample.ImageHandler, Sample" />
     </httpHandlers>

The verb part is just what you want it to respond to (GET, POST, etc.). Path is the file or file extension you want it to respond to and Type is - ClassName, Assembly. For the above web.config setting, each request to the getAvatarImage.img will be sent to the handler and the ProcessRequest will be executed. When we use a new file extension like "getAvatarImage.img" or "getAvatarImage.do," we need to create IIS extensions mapping for the new extensions.

We will be using the built-in extensions (.ashx) that are already mapped to ASP.NET so that we can avoid the necessity to modify the IIS extensions mapping. With .ashx extension, there is no requirement for registration in the web/machine.config.


View Entire Article

Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 5 and 4 and type the answer here:

User Comments

Title: give the informaion very easy format   
Name: venu
Date: 12/23/2008 9:51:31 AM
Comment:
u will provide the information very easy
Title: Thanks   
Name: Gabriel
Date: 11/27/2008 3:53:58 AM
Comment:
Thanks! That was easy and helpful.
Title: please provide the details of storing images in database using asp.net   
Name: danny
Date: 10/12/2007 9:36:01 AM
Comment:
please provide the same at the earliest
Title: Response to: Missing a Reference for dsImagesTableAdapters?   
Name: Mark
Date: 8/30/2007 9:51:30 AM
Comment:
My bad: I'd put the xsd and xss files in the app_data folder.

Excellent example!
Title: Missing a Reference for dsImagesTableAdapters?   
Name: Mark
Date: 8/30/2007 9:26:30 AM
Comment:
Where do we make the reference to the dsImagesTableAdapters?

thanks
Title: nice   
Name: abc
Date: 8/24/2007 1:30:55 AM
Comment:
nice concept
Title: ASP.NET   
Name: sadat arsalan
Date: 7/21/2007 1:17:42 PM
Comment:
tell me about buttons coding in ASP.NET using HTML codes
Title: Displaying Images in ASP.NET Using HttpHandlers   
Name: Electronic Screw
Date: 7/19/2007 5:34:45 AM
Comment:
Yes, you could do that and the content-type was the "key" to that. I'm writing on that and will be available in a couple of days.

Thanks
Title: Displaying Images in ASP.NET Using HttpHandlers   
Name: Jeff
Date: 7/18/2007 10:50:17 AM
Comment:
Could you use this same sort of set up to pull things like .doc or .pdf files that might be stored in a database?

Product Spotlight
Product Spotlight 






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2009 ASPAlliance.com  |  Page Processed at 11/21/2009 12:10:43 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search