We’ve all been there. Restoring a copy of the production database on your development or test-environment, start the site and you get a 404. Argh, I forgot to set the correct site definitions! Again!
Fig 1. The freaking site definitions
In a multi site environment you can have a lot of different site definitions, and it can take quite a while to update them all manually. So, I created a small initialization module that makes sure the site definitions are correct for the current environment.
This initialization module update the site definitions for the local development machine only, but it could easily be extended to any environment you might have. I’m checking the database connectionstring to see what environment we’re on, but you can of course use e.g. a setting in web.config, or check what domain is used.
Update: Also check Eric Petersson’s updated version of this code.
At time of writing I was using Episerver CMS 11.3