简体   繁体   English

共享不同Web应用程序的相同配置设置

[英]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: 例:

  • root folder: C:\\inetpub\\wwwroot 根文件夹: C:\\inetpub\\wwwroot
  • web app1 root folder: C:\\inetpub\\wwwroot\\webapp1 web app1根文件夹: C:\\inetpub\\wwwroot\\webapp1
  • web app2 root folder: C:\\inetpub\\wwwroot\\webapp2 web app2根文件夹: C:\\inetpub\\wwwroot\\webapp2

Now if 现在如果

  • root config is at: C:\\inetpub\\wwwroot\\web.config root config位于: C:\\inetpub\\wwwroot\\web.config
  • web app1 config at: C:\\inetpub\\wwwroot\\webapp1\\web.config web app1 config at: C:\\inetpub\\wwwroot\\webapp1\\web.config
  • web app2 config at: 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显式覆盖它们,否则app1app2都将从root web.config继承它们的配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 不同的应用程序设置取决于配置模式 - Different application settings depending on configuration mode 处理asp.net Web应用程序中的配置设置 - Handling configuration settings in asp.net web application 应用程序设置文件是否应与以不同语言编写的同一程序一起使用 - Should an application settings file work with the same program written in different languages c#应用程序和配置设置 - c# application and configuration settings 相同的Web服务项目,不同的配置,无法调试 - Same web service project, different configuration, can't debug Web应用程序中共享相同基本URL的两个web.config的共存 - Co-existence of two web.config in web application sharing same base url 如何在web.config中添加电子邮件配置设置并从中检索相同设置? - How to add email configuration settings in web.config and retrieve the same from it? 在不同程序集中共享应用程序数据 - Sharing application data in different assemblies 如何在应用程序和Windows服务之间共享相同的设置(或配置)(即使它们在不同的PC上运行) - How to share the same settings (or configuration) between apps and windows services (even if they run in different PCs) 在具有不同connectionStrings的两台不同服务器上部署同一Web应用程序? - Deploying same web application on two different servers with different connectionStrings?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM