3

我有两个不同的虚拟目录映射到操作系统上的同一目录。在其中一个虚拟目录中,我需要禁用浏览文件夹,而在另一个虚拟目录中,我需要启用它。

问题是当我改变其中一个时,另一个也发生了变化。我认为这个问题与两个虚拟目录都指向操作系统中的同一个文件夹有关,但是对于 IIS6,我有同样的配置没有问题。

有什么想法可以解决这个问题吗?

谢谢!

4

3 回答 3

6

IIS 7 确实使用目录中的 web.config 文件进行配置,但是,您也可以放弃使用 web.config 文件(即不要使用 IIS 管理器工具),而不是通过 IIS 管理器启用目录浏览,只需编辑您的 applicationHost.config 在您真正希望启用浏览的唯一虚拟目录上设置目录浏览。这将允许您浏览一个虚拟目录而不是另一个,即使两者都指向同一个物理目录。

下面是一个示例:编辑 applicationHost.config 文件。该文件可以在您的%WINDIR%\System32\inetsrv\config目录中找到。

1) 转到文件的底部。您应该在那里为配置部分找到一个 XML 结束标记:

</configuration>

2) 在该标签上方,使用以下指南添加位置标签:

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

将 {website name} 替换为相关网站的网站名称(如 IIS 管理器中所示),将 {path to virtual directory} 替换为您希望浏览的虚拟目录的路径。例子:

<location path="MyWebsite/imagelist">

现在假设在上面的示例中,imagelist是一个指向 {your webroot}/pics 的虚拟目录,而您还有另一个名为images的虚拟目录也指向 {your webroot}/pics。当访问者访问yoursite.com/images时,他们将看不到图像列表,但是当他们访问yoursite.com/imagelist时,他们将获得返回的目录列表。

于 2010-12-09T07:38:55.063 回答
1

有很多可能性,但我面临并解决的问题如下。

  1. IIS 中的 .NET 框架与 web.config 中指定的框架不匹配。将 IIS 中的框架更改为创建的项目之一。(如果创建的项目或解决方案是 4.5/4.0,则在您的网站高级设置下将 IIS 更改为 4.0。)

  2. 检查 web.config 中的标签是否为所有节点正确关闭。

这应该工作!

谢谢, 阿南德

于 2015-01-07T17:40:07.210 回答
0

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.)

于 2010-05-10T18:28:11.890 回答