In the case of connection strings, you can indeed specify a shared file. If the shared file is located on a UNC network, it requires administrative privileges on the computer on which the application will be hosted.
Decision. In your web.config, use configSource to point to the local configuration file. Due to .Net restrictions, this should be at or below the root of the configuration file. I just point to the file in the application folder itself:
<connectionStrings configSource="ConnectionStrings.config" />
In a shared location accessible to the application pool user, add a configuration file containing shared connection strings. This file should not contain any xml, except for the connectionStrings section itself. The general ConnectionStrings.config file is as follows:
<connectionStrings> <clear/> <add name="connString1" connectionString="connString1 info goes here"/> <add name="connString2" connectionString="connString2 info goes here"/> </connectionStrings>
Now the trick. Create a Windows symbolic link in the application folder, pointing to an external shared configuration file. To do this, you will need administrator rights:
mklink ConnectionStrings.config \\someServer\someShare\someFolder\ConnectionStrings.config
We just outsmarted .Net. The configuration system will use the configSource parameter to search for connection strings in the local ConnectionStrings.config file. A symbolic link looks like a file in .Net, and a symbolic link resolves to a shared configuration file.
Cautions. Changes to the shared file do not start restarting the application in .Net. In the case of IIS, the website or application pool will need to be restarted manually.
Due to the need for administrative privileges to create a symbolic link, this approach may not work for everyone. There are two related alternatives that can work if the shared file is on the same logical drive - hard links and connections. See this discussion and this discussion for more details.
Scott Aug 29 '16 at 20:21 2016-08-29 20:21
source share