简体   繁体   中英

sharing same configuration settings for different web application

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 ie 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?

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM