I have a solution composed of a web application and multiple projects, is it possible to share the configuration in the web application across all the solution?
Than
No, it is not possible. A web.config file need to be placed at the root folder of each web site. You could have a common web.config file copied to the root of each site as a build step of the project so that at runtime ASP.NET can find it.
I looks like it is possible, you can try following:
You can copy your web.config
file to the root folder of your solution. Then create solution folder (which does not belong to any of your projects) and add your file there (via Add Existing Item
popup menu item). Delete web configs from your web sites. After that you can select Add Existing Item
from popup menu on your both web projects, select your web.config file from the solution root and click Add As Link
. After that you will have links to your web config files instead of real ones in your solution.
On the other hand I'm not sure if sharing of the web.config files among different projects is a good idea, because usually web.config has some specific condifuration for each separate application.
Web.config files contain cascading overrides of a higher web.config file settings. So if you would place a web.config in the root of IIS or adjust settings in the machine.config or standard web.config of the .NET framework (C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG for example).
The best example's probably the use of the LocalSqlServer connection string. It's defined in the machine.config as
<connectionStrings>
<add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;
Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;
User Instance=true" providerName="System.Data.SqlClient"/>
</connectionStrings>
If you would use the Login control for example and would debug and request the connectionstrings then this one will be included as well.
So if you need some settings common to multiple applications place them in a web.config file which is high enough in the hierarchy, ultimately in the machine.config.