1

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?

Community
  • 1
  • 1
Billa
  • 5,226
  • 23
  • 61
  • 105
  • IIS has a "Shared configuration" concept, may be they wanted to hear about that. – sunil Mar 28 '13 at 17:49
  • 1
    was that recruitment interview? Why didn't you ask what was wrong? :) – jan salawa Mar 28 '13 at 17:51
  • Remember just because you're in an interview doesn't automatically make them the authority on right vs wrong. If you are confident in your answer defend it, otherwise ask them how they would do it. It's not really fair if they are asking all of the questions. – The Muffin Man Mar 28 '13 at 21:39

2 Answers2

4

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.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444
  • Its really great. I referred http://stackoverflow.com/questions/6940004/asp-net-web-config-configsource-vs-file-attributes and got more on this! – Murali Murugesan Mar 29 '13 at 06:09
1

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:

  • root folder: C:\inetpub\wwwroot
  • web app1 root folder: C:\inetpub\wwwroot\webapp1
  • web app2 root folder: C:\inetpub\wwwroot\webapp2

Now if

  • root config is at: C:\inetpub\wwwroot\web.config
  • web app1 config at: C:\inetpub\wwwroot\webapp1\web.config
  • web app2 config at: 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.

Xaqron
  • 29,931
  • 42
  • 140
  • 205