Quick DD4T tip : combine ‘static’ images and images handled with the BinaryDistributionModule

In a DD4T website, you can serve images from the broker using the BinaryDistributionModule. This is a module that intercepts requests for any images, and then queries the broker for published images, and serves them (I will talk about this more in-depth in a future post).

However, this might give some problems if you also have static images.

In our current implementation, we are using this module, but this caused problems with ‘static’ images that are not in the broker, but that are just on the webserver (we use these static images mainly for css related stuff (backgrounds, some icons,…)

The problem was that the binarydistributionmodule was also intercepting requests for these images, but as they couldn’t find these in the broker, they never showed up in the browser.

To get this working, you just need to make two small changes in your web application

Let’s assume that all of your ‘static’ images are stored in a folder “content”

Then, the only thing to do to exclude this folder from being handled by this module is

– change the web.config appsetting “DD4T.BinaryUrlPattern” to

<add key="DD4T.BinaryUrlPattern" value="^(?!(\/content\/)).*\.(jpg|png|gif|jpeg)$" />

This regex is used by the module to make sure it only handles certain requests. In this case, the regex means : handle all requests for jpg,gif or png files, if they are not in a folder named “content”

– Another thing to do is to update your routing configuration.

All you need to add to your routeconfig.cs file is this line of code


Once this is done, just build your project, and all image requests will be handled by the binarydistributionmodule, except any images you place in the “/content” folder.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>