IIS browse directory problem on a virtual directory

user335518 picture user335518 · May 10, 2010 · Viewed 16.6k times · Source

I have two differents virtual directories mapping to the same directory on the OS. In one of this virtual directories I need to have the browse folders disable, and in the other one I need to have it enable.

The problem is that when I changed one of them the other change as well. I thinks this problem is related that both virtual directories points to the same folder in the OS, but with the IIS6 I had this same configuration with out a problem.

Any idea of a work around with this?

Thanks!

Answer

Thurnok picture Thurnok · Dec 9, 2010

IIS 7 does indeed use the web.config file in directories for configuration, however, you can also forego using the web.config file (i.e. do not use the IIS Manager tool) and instead of enabling directory browsing through the IIS Manager, simply edit your applicationHost.config to setup directory browsing on the one and only virtual directory you actually want the browsing enabled. This will allow you to have browsing in one virtual directory but not another even when both point to the same physical directory.

Here's an example: Edit the applicationHost.config file. This file can be found in your %WINDIR%\System32\inetsrv\config directory.

1) Go to the bottom of the file. You should find an XML closing tag there for the configuration section:

</configuration>

2) above that tag, add a location tag using the following as a guide:

 <location path="{website name}/{path to virtual directory}">
      <system.webServer>
           <directoryBrowse enabled="true" />
      </system.webServer>
 </location>

Replace {website name} with the website name (as seen in IIS Manager) for the website in question and {path to virtual directory} with the path to the virtual directory you want browsing to be available. Example:

<location path="MyWebsite/imagelist">

Now let's say in the above example, imagelist is a virtual directory that points to {your webroot}/pics and you have another virtual directory called images that also points to {your webroot}/pics. When a visitor goes to yoursite.com/images they will not see the image list, but when they go to yoursite.com/imagelist they will get a directory listing returned.