Dynamic Images
First post of the new year!
An interesting ASP.NET 2.0 solution that can easily be back-propagated to ASP.NET 1.x is the DynamicImage control which in Whidbey partners the familiar Image control. I don't really know how many people really used the <asp:Image> control over the static and more efficient <img src=""> or at least the <img runat=server> tag. However, the Image control doesn't help a little to create more neatly and elegantly code that retrieves image bytes from a database.
DynamicImage does it, and very well, through a built-in HTTP handler named cachedimageservice.axd. The control gets the data and makes a copy to the ASP.NET cache using a GUID as the key. Next, when it comes to generating the markup, the <img> tag is made point to handler with a data parameter that references the GUID.
Why HTTP handlers? Because a HTTP handler is more efficient (lightweight, exactly) than a page. And this is a good advice also for ASP.NET 1.x if you play with dynamic images.
DynamicImage can get images in four ways--GDI+ objects, URLs, array of bytes, ASP.NET 2.0 generators. Do not use plain URLs with this control (the related property is ImageFile). Use the Image control instead which exploits the IIS capability of quick serving image files. The ImageFile property is only useful if you write dual apps, desktop and mobile. In this case, the DynamicImage control offers extra service like automatic adaptation of type and size to the browser's caps.
Really cool stuff!