Skip to main content
 首页 » 编程设计

c#之如何将页面指向不同的 web.config

2024年01月31日31xing901022

ASP .NET 中的页面是否可以指向不同的 web.config?例如,我有 2 个不同的配置文件,一个是 web.config,另一个是 web1.config。如何在 ASP .NET 中将页面指向 web1.config?

请您参考如下方法:

据我所知,您不能将页面指向不同的 web.config 文件。但是,您可以将您的网站/应用程序组织到子文件夹中,在根文件夹中有一个主要的 web.config 文件,在子文件夹中有一个新的 web.config 文件用于子文件夹的特定设置。然后您可以复制此子文件夹并修改其 web.config 以进行不同的设置。

我的想法是在子文件夹中设置一个虚拟目录,而不是制作文件副本,这样您就可以重复使用相同的网站/应用程序并使用不同的 web.config 文件对其进行控制。我以前没有尝试过,但我认为值得一试!

Web.config Inheritance and Overrides

Each Web.config file applies configuration settings to the directory that it is in and to all of the child directories below it. Settings in child directories can optionally override or modify settings that are specified in parent directories. Configuration settings in a Web.config file can optionally be applied to individual files or subdirectories by specifying a path in a location element.