IIS web.config:从特定服务器提供服务时显示目录列表?

在IIS中,我希望从testing服务器提供服务时启用目录列表。 使用相同的web.config我不希望在生产服务器上启用目录列表。 这可能吗?

在testing服务器和生产服务器上都安装了相同的整个目录结构。

我目前的web.config如下所示:

 <?xml version="1.0" encoding="UTF-8"?> <configuration> <location path="."> <system.webServer> <directoryBrowse enabled="false" /> </system.webServer> </location> <location path="this/directory/listing/should/only-show-on-test-server"> <directoryBrowse enabled="true" /> </system.webServer> </location> 

你有两个select:

  1. 创build一个主要引用的辅助web.config文件,该文件的内容将因服务器而异。

你的主web.config将有:

 <?xml version="1.0" encoding="UTF-8"?> <configuration> <location path="."> <system.webServer> <directoryBrowse enabled="false" /> </system.webServer> </location> <location path="foo"> <system.webServer> <directoryBrowse configSource="ServerSpecificDirectorySettings.config" /> </system.webServer> </location> </configuration> 

第二个文件ServerSpecificDirectorySettings.config只是:

 <directoryBrowse enabled="true" /> 
  1. 将服务器特定的configuration从web.config文件移到ApplicationHost.config文件中的location节点中。

这两个解决scheme都有优点和缺点,我想这取决于你如何部署你的网站。 如果你想保持所有的文件完全相同的每台服务器上,你必须去第二个选项。 但是对于x-copy部署,第一个选项是更好的。