HTTP 304 response handling in Sitecore MediaRequestHandler

Whilst testing a Sitecore 6.1 site due for release Firebug highlighted some unexpected behaviour from the Sitecore Media Request Handler which takes care of responding to requests for items held in the Sitecore Media Library. Media library items were being returned in full every time that they were requested, each returning a HTTP 200 response status code.

Further digging with Lutz Roeder’s excellent Reflector tool showed that the If-Modified-Since request header field was not being responded to correctly by the MediaRequestHandler. The If-Modified-Since request header is a HTTP-date value whose time component is in the format HH:MM:SS (i.e. no milliseconds). This header field value is used by the Modified method within the MediaRequestHandler to compare to the System.DateTime value that the media library item was last updated. As a System.DateTime value includes a milliseconds component the equality check fails for the majority of media library requests and as a result the item is downloaded to the browser in full.

Sitecore have confirmed that this is a known issue and something that will be fixed in a forthcoming release. In the meantime it’s not difficult to patch in a modified HTTP handler to respond to media library requests and implement HTTP 304 response handling appropriately. Alex de Groot has a good article on his blog that explains how Sitecore interacts with HTTP handlers for media handling.


6 thoughts on “HTTP 304 response handling in Sitecore MediaRequestHandler

  1. Just spotted the same thing myself on a customer site using the most excellent Redbot (

    All the .ashx image assets failed the IMS (if-modified-since) test.


    • Thanks Steve,

      I’ve been meaning to follow up on this to see whether Sitecore have pushed a fix out for this into their current release. If it’s still broke I can put up my patched version of the media handler if it’s of use.


  2. Thanks Kevin – if you could post up what Sitecore says that would be great. I don’t have access to Sitecore support myself. Hopefully the client will chase it direct too.

    • Steve, this problem has been resolved with the release of Sitecore CMS 6.4.1 rev.110324 (6.4.1 Update-1) on March 28, 2011.

      According to the release notes there’s a whole pile of issue fixes and improvements in the area of the Media API. Here’s the Sitecore reference for the fix that you’re interested in:

      Sitecore parsed and compared timestamps in the “If-Modified-Since” HTTP header incorrectly, causing the server to never return a “304 Not Modified” response. This prevented browsers from using their cached versions of media files and caused unnecessary data to be transferred from the server to the client. (320278, 325114).

      Please be aware that Sitecore CMS 6.4.1 rev.110324 (6.4.1 Update-1) is not Sitecore’s current recommended version, as such is not recommended for a production installation that runs an important website for a customer. The current recommended version is Sitecore CMS 6.3.1 rev.110112.


  3. Pingback: Media Library status code 200 Vs 304 « Sitecore basics!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s