This project is read-only.

ASP.NET Photo Handler

Jun 21, 2007 at 7:45 AM
Edited Jun 21, 2007 at 7:46 AM
In June 2005, Dmitry posted a very simple photo album on his blog. I immediately liked it because it's both easy to set-up (just drop the ashx file into your web site's photo directory) and to manage (no need to upload images one by one using a clumsy web upload field, just upload new photos using ftp or the file system). It's also nice to browse. Sure, there are no fancy ratings or comments features, you can't add titles or descriptions, but frankly, I didn't need all these features.

Still, I wanted to change a few things so I went ahead and added the following to Dmitry's handler:

  • XHTML output
  • CSS styling
  • EXIF meta-data reading and displaying
  • Sorting by date shot
  • Stacked photos folder icons
  • Folder names respect casing and special characters
  • In-handler pseudo-config (just modify the handler's configuration block with any text editor)
  • Thumbnail caching on disk or in memory

The thumbnail caching on disk is an essential improvement because if you have a large number of heavy pictures, memory won't be the right place to cache. If the handler is configured to save on disk (which is the default), the thumbnails are stored in the application's temporary folder, the very same place where pages are compiled. This means that you don't need to set writing permissions, but it also means that you need to run in high or full trust. If you can't do that, you should configure the handler to cache in memory or not at all.

The handler is under the MS-PL licence, which means that you can do pretty much what you want with it. It uses the Metadata public domain library by Drew Noakes and adapted for .NET by Renaud Ferret to extract the EXIF information from the jpeg files. This library can be downloaded from