Thursday, August 14, 2008

Retrieve images from Database using ASHX

Most of articles (which I found) about retrieve images from database are using Response.writebanary(...) to aspx file, then point the image's url to this aspx file. It worked fine for the most asp.net website. The luck ran out for me when I tried to implement a module for a dnn site. Because DNN only allows the user control (ascx) files, I had trouble to imped the image on my user control inside the DNN. The DNN will log me out every time after I displayed an image from the database.

The solution is quite simple, but took me a while to found it. Instead of using the aspx page as the image url to display the image on the page, use ASHX (HTTPHandle) file instead. The code used inside the ASHX file is almost the same as in the ASPX page.

For more detail on how to retrieve the image from database using ASHX: Go here

No comments: