[英]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. 如何为在同一IIS下运行的不同Web应用程序共享相同的配置设置。
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 可以通过将其移动到CLR版本下的根级web.config / machine.config文件来完成,即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. 将xml文件或某个文件放在服务器的磁盘上,并使用System.IO进行读取。
Older way, put some .ini file and read it 更老的方式,放一些.ini文件并阅读它
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. 一个选项:您可以在任何配置元素上使用configSource
属性,以使其从外部文件中提取配置。
ConnectionStrings.config ConnectionStrings.config
<connectionString>
...
</connectionStrings>
Web.config Web.config文件
<connectionStrings configSource="ConnectionStrings.config" />
Then, you can link ConnectionStrings.config between your projects and you're good to go. 然后,您可以在项目之间链接ConnectionStrings.config,然后就可以了。
You don't need to do anything. 你不需要做任何事情。 default behavior is inheriting configurations from root folder by all web applications in sub-folders. 默认行为是子文件夹中的所有Web应用程序从根文件夹继承配置。 You just overwrite which one you need. 你只需覆盖你需要的那一个。
Example: 例:
C:\\inetpub\\wwwroot
根文件夹: C:\\inetpub\\wwwroot
C:\\inetpub\\wwwroot\\webapp1
web app1根文件夹: C:\\inetpub\\wwwroot\\webapp1
C:\\inetpub\\wwwroot\\webapp2
web app2根文件夹: C:\\inetpub\\wwwroot\\webapp2
Now if 现在如果
C:\\inetpub\\wwwroot\\web.config
root config位于: C:\\inetpub\\wwwroot\\web.config
C:\\inetpub\\wwwroot\\webapp1\\web.config
web app1 config at: C:\\inetpub\\wwwroot\\webapp1\\web.config
C:\\inetpub\\wwwroot\\webapp2\\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
. 除非在自己的web.config
显式覆盖它们,否则app1
和app2
都将从root web.config
继承它们的配置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.