Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to split app/web.config into 2 files?

I currently use app/web.config to store Connection Strings for my database, which means on upgrade we do not touch the config files to preserve those strings. However we now want to move to MVC5 and doing so requires all the library definitions to be updated within the app/web.config (we have both an App and a website with similar configuration).

So is it possible to split these files into two files so that I can update the library definitions whilst keeping intact my existing infrastructure to read out the connection strings from the .config files? Or is there another method to deal with this?

like image 314
Chris Avatar asked Mar 27 '14 11:03

Chris


People also ask

Can we have two web config files for a Web application?

Yes you can have two web. config files in application. There are situations where your application is divided in to modules and for every module you need separate configuration. For example if you have a application which has two modules lets say accounts and sales.

How do I use different web config files?

config (or any file) when you press F5 in Visual Studio. You can have different transformations based on the build configuration. This will enable you to easily have different app settings, connection strings, etc for Debug versus Release. If you want to transform other files you can do that too.


1 Answers

Yes; you simply create a second file rather than including things inline, for example:

<configuration>
    <connectionStrings configSource="connections.config"/>
</configuration>

The connections.config file would start with <connectionStrings>...</connectionStrings>.

like image 127
Marc Gravell Avatar answered Oct 16 '22 06:10

Marc Gravell