Reputation: 5266
This is a question asked in my interview today.
How do i share same configuration settings for different web applications running under a same IIS.
I answered,
Can be done by moving same into root level web.config/machine.config file under a CLR version i.e Windows/Microsoft VS .Net/Framework/Version/Config/filename
Have a xml file or some file located on a disk of the server and read using System.IO.
Older way, put some .ini file and read it
Finally they said all are wrong! Like to know what could be the way to do this?
Upvotes: 1
Views: 801
Reputation: 30837
You don't need to do anything. default behavior is inheriting configurations from root folder by all web applications in sub-folders. You just overwrite which one you need.
Example:
C:\inetpub\wwwroot
C:\inetpub\wwwroot\webapp1
C:\inetpub\wwwroot\webapp2
Now if
C:\inetpub\wwwroot\web.config
C:\inetpub\wwwroot\webapp1\web.config
C:\inetpub\wwwroot\webapp2\web.config
both app1
and app2
will inherit their configurations from root web.config
unless override them explicitly in their own web.config
.
Upvotes: 1
Reputation: 239220
One option: You can use the configSource
attribute on any configuration element to have it pull the configuration from an external file.
ConnectionStrings.config
<connectionString>
...
</connectionStrings>
Web.config
<connectionStrings configSource="ConnectionStrings.config" />
Then, you can link ConnectionStrings.config between your projects and you're good to go.
Upvotes: 4