IIS browse directory problem on a virtual directory
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开发者_如何学C this same configuration with out a problem.
Any idea of a work around with this?
Thanks!
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.
There are many possibilities, but what I faced and fixed it is as below.
.NET framework in IIS not matching with the one specified in web.config. Change the framework in IIS to the one of which project created. (if project or solution created is 4.5/4.0 then change in IIS to 4.0 under your website advance settings.)
Check for the tags in web.config closed properly for all the nodes.
This should work!!
Thanks, Anand
The reason why it is different behavior from IIS6 is that IIS6 stored the property for allowing directory browsing in the IIS6 Metabase DirBrowseFlags property of the virtual directory, which has a unique entry for each virtual directory, whereas in IIS7, that property is now stored only in the Web.config
file:
<system.webServer>
<!-- ... -->
<directoryBrowse enabled="true" />
</system.webServer>
Since both your virtual directories in IIS7 share the same physical directory, they both share the same Web.config
file, and so you'll find that changing the property in one causes the change to appear in the other, as they're both modifying the same Web.config
file.
(I don't of know a good workaround to this for IIS7 for you at the moment.)
精彩评论