I you have an image gallery with dynamically generated thumbnails; you should make sure that the browser is told to cache the thumbnails. If not, each image is generated every time the browser visits. It stresses the CPU unnecessary and the page takes longer to load. If the images where in the browsers cache, the page would load much faster and the images would not be generated on each page request.

If the image gallery consists of multiple pages the visitor can navigate between, the chances are that he or she will visit the same page more than once. For returning visitors, the chances are much higher.

In order to enable browser caching you have to set the Last-Modified header in the .aspx or .ashx that you use to generate the thumbnails.

Here’s an example on how it could be done:

Response.Cache.SetLastModified(DateTime.Now.AddYears(-1));

That’s all there is to it, and best of all - it’s supported by all major browsers.

I’ve been getting a strange exception lately from my automatic ASP.NET e-mail exception logging service. It sends me this exception:

The remote host closed the connection. The error code is 0x80072746.
   at System.Web.Hosting.ISAPIWorkerRequestInProcForIIS6.FlushCore(Byte[] status, Byte[] header, Int32 keepConnected, Int32 totalBodySize, Int32 numBodyFragments, IntPtr[] bodyFragments, Int32[] bodyFragmentLengths, Int32 doneWithSession, Int32 finalStatus, Boolean& async)
   at System.Web.Hosting.ISAPIWorkerRequest.FlushCachedResponse(Boolean isFinal)
   at System.Web.Hosting.ISAPIWorkerRequest.FlushResponse(Boolean finalFlush)
   at System.Web.HttpResponse.Flush(Boolean finalFlush)
   at System.Web.HttpResponse.Flush()
   at StripHandler.ProcessRequest(HttpContext context)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

This exception is not visible to the visitors of the website. It all happens behind the scenes. For some reason the ISAPIWorkerRequestInProcForIIS6 class is totally undocumented on MSDN and a Google search didn’t find anything about it either. It appears that this class does not exist. If you have any idea about this strange exception, please let me know.