A simple example of using httphandler in ASP.NET 2.0

Let's started by creating a new web application in Visual Studio 2008 Team Suite.

Step 1:
create a class named PhotoManager to manage our photoes. In this class, we store the binary data in a memory stream no matter what the binary data comes from. (It may be from the database, or we create the image at real time, etc..)

PhotoManager class


Step 2: Add a generic handler named MyHandler.ashx to the application. This handler will write the stream into our httpcontext.

MyHandler Class


Step 3: Use our images in the .aspx file and display it.

<img src="MyHandler.ashx" style="border:solid 4px white" alt="Photo from handler" />


The Result:

Happy coding!!

posted @ 2009-04-16 17:28  Roahn Luo  阅读(190)  评论(0)    收藏  举报