Simon Harriyott

ASP.NET themes and hosting multiple sites from a single app

I'm currently writing several sites with the same functionality. Hosting them all from one directory is straightforward, by adding virtual directories in IIS.

Changing the images, CSS and colours is easy enough using themes. Web.Config settings are a different matter. As themes support XML files, a config file can be added to each theme. Once added, they can be accessed by using the theme name:

ExeConfigurationFileMap exe = new ExeConfigurationFileMap();
exe.ExeConfigFilename = Server.MapPath("~/App_Themes/" + Page.Theme + "/SiteSettings.config");
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(exe, ConfigurationUserLevel.None);

The application settings can be accessed thus:

13 June 2007