如何在目录浏览中隐藏web.config?

问题描述 投票:0回答:3

我使用 IIS8,我试图从我网站的文件列表中隐藏 web.config,但我似乎找不到解决方案。你能帮我吗? :)

iis
3个回答
47
投票

右键单击该文件并将其标记为隐藏。它将停止显示在 IIS 目录浏览中。


3
投票

对每个 web.config 文件使用命令提示符

attrib +H web.config

您还可以使用 Windows 资源管理器进行查找,并在存储所有 Web 数据的目录中搜索“web.config”,然后右键单击其中的每个数据以启用隐藏标志。使用“查找 GUI”>“查看”选项 - 您可以隐藏已经隐藏的文件,以便您知道哪些文件已更改。


0
投票

我能够通过

解决这个问题
  1. 将所有配置选项从可浏览目录的
    web.config
    文件移动到站点范围
    location
    文件中的新
    web.config
    元素中
  2. 从可浏览目录中删除
    web.config
    ,这样它既不会出现在目录列表中,也不会由 IIS 提供服务

之前

C:\inetpub\wwwroot\mysubdirectory\web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <directoryBrowse enabled="true" />
    </system.webServer>
</configuration>

/mysubdirectory/web.config
出现在目录列表中并提供服务。

之后

C:\inetpub\wwwroot\web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <directoryBrowse enabled="false" />
        <!-- other existing site-wide settings -->
    </system.webServer>

    <!-- moved from C:\inetpub\wwwroot\mysubdirectory\web.config -->
    <location path="mysubdirectory">
        <system.webServer>
            <directoryBrowse enabled="true" />
        </system.webServer>
    </location>
</configuration>

C:\inetpub\wwwroot\mysubdirectory\web.config

已删除

现在我仍然可以列出

mysubdirectory
中的其他文件,但
web.config
不再是其中之一。如果您尝试导航到
/mysubdirectory/web.config
,IIS 也会正确返回 404。

© www.soinside.com 2019 - 2024. All rights reserved.