0

In IIS I want directory listing to be enabled when served from the test server. With the same web.config I don't want directory listing to be enabled on the production server. Is this possible?

The same entire directory structure is mounted on both test and production servers.

My current web.config looks like:

<?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>

the
  • 468
  • 8
  • 23

1 Answers1

1

You have two options:

  1. Create a secondary web.config file referenced by the main one, the content of that file will differ from server to server.

Your main web.config would have:

<?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>

the second file ServerSpecificDirectorySettings.config has just:

<directoryBrowse enabled="true" />
  1. Move the server specific configuration from the web.config file into location nodes in the ApplicationHost.config file.

Both solutions have pros and cons, I guess it depends a bit on how you deploy your sites. If you want to keep all the files exactly the same on every server you have to go with the second option. But for an x-copy deployment the first option is better.

Peter Hahndorf
  • 13,763
  • 3
  • 37
  • 58