Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have multiple sites in IIS, each has its own configuration file for connection strings (connections.config).
HTML
<connectionStrings>   
    <add name="ServerDataConnection" connectionString="connection1" />    
    <add name="UserManagementModel" connectionString="connection2" />
   <add name="BlobStorageConnection" connectionString="connection3" />
</connectionStrings>

I reference the file in each site inside Web.config as follows:
HTML
<connectionStrings configSource="connections.config" />

I want to use only one connections.config for all sites.

What I have tried:

I tried to place the .config file in the root directory and use it for all sites, but I cannot find a way to reference it (get the path)? How can I do it this way?

If there are any other ways to do it I'll be glad to have your answers.

Thanks
Posted
Updated 11-May-20 6:31am
v2

You may want to look into the hierarchy of the config files; in particular ApplicationHost.config and if you can place your "common" portions of your various web.config files in there and just inherit them.

References:
MS Docs=> Configuration Reference=> IIS Configuration[^][^]
MS Docs=> Introduction to ApplicationHost.config[^]
 
Share this answer
 
Using configSource requires a physical file in either the same directory as the main config file, or a subdirectory. You can't refer to a file in a parent directory, and you can't use virtual directories to get around the limitation.

You could potentially create a hard link[^] to the common config file, which would make the same file appear in more than one directory.
mklink /h connections.config ..\connections.config
mklink | Microsoft Docs[^]

Otherwise, you'll need to add the settings to the application-wide configuration. The easiest way to do that would be to use the "Configuration Editor" option in IIS Manager.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900