Using Separate Files for Config Sections

Many people host more than one mojoPortal site and upgrading all of their sites can become very complex and cumbersome. This article will shed some light on the ability to separate some of the web.config configuration settings into individual files.

Note: This is an advanced topic and use of the items discussed here are not beneficial for most mojoPortal installations.

configSource

Okay, so a configuration option isn't really the key to happiness but this one will make your life easier so you can focus on whatever it is that does make you happy. configSource is an attribute that can be applied to a web.config section to instruct the .NET application to find the actual configuration for the section in another file. Use of configSource in a few sections of the mojoPortal web.config file will make updating multiple sites a lot easier. When upgrading a mojoPortal installation, it is best practice to use the web.config file that comes with release. The main reason for this is because new settings can be in the web.config file and other settings could have been changed since you last upgraded. The problem that arises is that there are two sections of the web.config that changes must be made to because those sections contain site specific settings.

The machineKey section contains site specific settings. If you don't use a custom machineKey for your site, please see this page. When you have a lot of mojoPortal installations to upgrade, you have to modify the web.config for each site which can be very time consuming and the process is prone to user error. You may have a script that copies all of the release files to each of mojoPortal installations; the unique settings in each sites' web.config can defeat much of the purpose of your script. The configSource attribute remedies the dilemma altogether. Using this technique, you can set all of your sites to use external files for these sections, and then when you update the sites, you only need to modify the web.config once and all of your sites unique settings will be retained.

One could use the configSource attribute on other sections of the web.config but we will only focus on the machineKey section. 

machineKey configSource

To use configSource on the machineKey, copy the entire machineKey section to a new file. Name the new file machineKey.config (you can name it whatever you like but you should absolutely use the .config section to keep people from downloading the file). Next change the machineKey section in the web.config to only have the configSource attribute specifying the machineKey.config file. The result should be:

web.config File

...other web.config sections...
<machineKey configSource="machineKey.config" />
...other web.config sections... 

machineKey.config File

Please note: you should not use the machineKey below. You should generate your own as described here.

<?xml version="1.0"?>
<machineKey
validationKey="55BA53B475CCAE0992D6BF9FE463A5E97F00C6C16DA3D7DF9202E560078AB501643C15514785FEE30FEF26FC27F5CE594B42FFCA55452EF90E8A056B4DAE9F39"
decryptionKey="939232D527AC4CD3E449441FE887DA110A16C1A36924C424CBAAE3F00282436C"
validation="SHA1"
decryption="AES" />