Is it possible to configure an IIS site to read ASP.Net settings from a site OTHER than web.config?
是否可以配置IIS站点从web.config以外的站点读取ASP.Net设置?
We'd like to have three config files in our codebase -- web-dev.config, web-test.config, and web-prod.config. Each IIS instance would be configured to read from their specific file. This way we have version control them all next to each other (and one-click deploy the entire site) but know that each IIS instance will read the settings specific to itself.
我们希望在代码库中有三个配置文件 - web-dev.config,web-test.config和web-prod.config。每个IIS实例都将配置为从其特定文件中读取。这样我们就可以将它们彼此相邻地进行版本控制(并且一键式部署整个站点),但是知道每个IIS实例都将读取特定于自身的设置。
I've found in IIS where it shows where the web.config is, but I can't see how to change the location.
我在IIS中找到了它显示web.config的位置,但我看不到如何更改位置。
5 个解决方案
#1
The best solution right now is to use different configs for development and production. This however will change with .net 4 and VS 2010 which they have added Web.Debug.config, Web.Release.config, Web.Staging.config and Web.Testing.config which will then publish the config you need in relation to the environment.
现在最好的解决方案是使用不同的配置进行开发和生产。然而,这将改变.net 4和VS 2010,他们已经添加了Web.Debug.config,Web.Release.config,Web.Staging.config和Web.Testing.config,然后将发布您需要的配置。环境。
#2
I use the configSource property to specify an external config file for sections that need different values for dev and production.
我使用configSource属性为需要不同的开发和生产值的部分指定外部配置文件。
<connectionStrings configSource="Config\ConnDev.config"/>
Then you only have to change one setting (manually or with a tool) to switch from Dev to Production configs.
然后,您只需更改一个设置(手动或使用工具)即可从Dev切换到生产配置。
#3
At my company we just have our deployment tool set to copy the appropriate file to web.config depending on what kind of deployment we're doing.
在我的公司,我们只需将我们的部署工具设置为根据我们正在进行的部署类型将相应的文件复制到web.config。
#4
I believe it has to be named web.config.
我相信它必须命名为web.config。
You are facing a common problem.
你正面临一个共同的问题。
One solution that I have used that worked really well in a large organization was to set environment variables on the web servers. Such as DEV, QA, UAT, PROD. Then, in code, you can query the environment variable to see which machine you are on, and then choose the values of appSettings accordingly. For example, you could have a database connection string named DEVconnection, and another named UATconnection. If your code determines from the environment variable that you are on UAT, then it would use UATconnection.
我使用过的一个在大型组织中运行良好的解决方案是在Web服务器上设置环境变量。如DEV,QA,UAT,PROD。然后,在代码中,您可以查询环境变量以查看您所在的计算机,然后相应地选择appSettings的值。例如,您可以拥有一个名为DEVconnection的数据库连接字符串,另一个名为UATconnection。如果您的代码根据环境变量确定您在UAT上,那么它将使用UATconnection。
This does assume that you have the ability to set environment variables on the web server. In this instance, the admins running the servers were the ones who suggested this solution.
这确实假设您能够在Web服务器上设置环境变量。在这种情况下,运行服务器的管理员是建议此解决方案的管理员。
What was sweet about this was that there was ever only one version of web.config.
关于这一点的甜点是,只有一个版本的web.config。
#5
I do not think we can make web.config declaratively so that we can specify different config file. One thing you can do you can split your configuration file and set for different environments. Please go through this article http://jetmathew.wordpress.com/2011/02/07/split-web-config-for-different-environment/
我认为我们不能以声明方式创建web.config,以便我们可以指定不同的配置文件。您可以做的一件事是拆分配置文件并设置不同的环境。请仔细阅读这篇文章http://jetmathew.wordpress.com/2011/02/07/split-web-config-for-different-environment/
cheers
#1
The best solution right now is to use different configs for development and production. This however will change with .net 4 and VS 2010 which they have added Web.Debug.config, Web.Release.config, Web.Staging.config and Web.Testing.config which will then publish the config you need in relation to the environment.
现在最好的解决方案是使用不同的配置进行开发和生产。然而,这将改变.net 4和VS 2010,他们已经添加了Web.Debug.config,Web.Release.config,Web.Staging.config和Web.Testing.config,然后将发布您需要的配置。环境。
#2
I use the configSource property to specify an external config file for sections that need different values for dev and production.
我使用configSource属性为需要不同的开发和生产值的部分指定外部配置文件。
<connectionStrings configSource="Config\ConnDev.config"/>
Then you only have to change one setting (manually or with a tool) to switch from Dev to Production configs.
然后,您只需更改一个设置(手动或使用工具)即可从Dev切换到生产配置。
#3
At my company we just have our deployment tool set to copy the appropriate file to web.config depending on what kind of deployment we're doing.
在我的公司,我们只需将我们的部署工具设置为根据我们正在进行的部署类型将相应的文件复制到web.config。
#4
I believe it has to be named web.config.
我相信它必须命名为web.config。
You are facing a common problem.
你正面临一个共同的问题。
One solution that I have used that worked really well in a large organization was to set environment variables on the web servers. Such as DEV, QA, UAT, PROD. Then, in code, you can query the environment variable to see which machine you are on, and then choose the values of appSettings accordingly. For example, you could have a database connection string named DEVconnection, and another named UATconnection. If your code determines from the environment variable that you are on UAT, then it would use UATconnection.
我使用过的一个在大型组织中运行良好的解决方案是在Web服务器上设置环境变量。如DEV,QA,UAT,PROD。然后,在代码中,您可以查询环境变量以查看您所在的计算机,然后相应地选择appSettings的值。例如,您可以拥有一个名为DEVconnection的数据库连接字符串,另一个名为UATconnection。如果您的代码根据环境变量确定您在UAT上,那么它将使用UATconnection。
This does assume that you have the ability to set environment variables on the web server. In this instance, the admins running the servers were the ones who suggested this solution.
这确实假设您能够在Web服务器上设置环境变量。在这种情况下,运行服务器的管理员是建议此解决方案的管理员。
What was sweet about this was that there was ever only one version of web.config.
关于这一点的甜点是,只有一个版本的web.config。
#5
I do not think we can make web.config declaratively so that we can specify different config file. One thing you can do you can split your configuration file and set for different environments. Please go through this article http://jetmathew.wordpress.com/2011/02/07/split-web-config-for-different-environment/
我认为我们不能以声明方式创建web.config,以便我们可以指定不同的配置文件。您可以做的一件事是拆分配置文件并设置不同的环境。请仔细阅读这篇文章http://jetmathew.wordpress.com/2011/02/07/split-web-config-for-different-environment/
cheers