概述
<hiddenSegments> 集合的 <add> 元素指定要添加到 Internet Information Services (IIS) 7 隐藏段集合的唯一 URL 段。
注意
当请求筛选因 URL 段隐藏而阻止 HTTP 请求时,IIS 7 将向客户端返回 HTTP 404 错误,并记录以下 HTTP 唯一子状态,以确定拒绝请求的原因:
| HTTP 子状态 | 说明 | 
|---|---|
404.8 | 
隐藏命名空间 | 
此子状态允许 Web 管理员分析其 IIS 日志并识别潜在威胁。
兼容性
| 版本 | 说明 | 
|---|---|
| IIS 10.0 | <add> 元素在 IIS 10.0 中未进行修改。 | 
| IIS 8.5 | <add> 元素在 IIS 8.5 中未进行修改。 | 
| IIS 8.0 | <add> 元素在 IIS 8.0 中未进行修改。 | 
| IIS 7.5 | <hiddenSegments> 元素在 IIS 7.5 中未进行修改。 | 
| IIS 7.0 | IIS 7.0 中引入了 <hiddenSegments> 集合的 <add> 元素。 | 
| IIS 6.0 | <hiddenSegments> 元素替代了 IIS 6.0 UrlScan [DenyUrlSequences] 功能。 | 
安装
IIS 7 及更高版本的默认安装包括请求筛选角色服务或功能。 如果卸载请求筛选角色服务或功能,可以使用以下步骤重新安装它。
Windows Server 2012 或 Windows Server 2012 R2
- 在任务栏上,单击 “服务器管理器”。
 - 在“服务器管理器”中,单击“管理”菜单,然后单击“添加角色和功能”。
 - 在“添加角色和功能”向导中,单击“下一步”。 选择安装类型,然后单击“下一步”。 选择目标服务器,然后单击“下一步”。
 - 在“服务器角色”页上,依次展开“Web 服务器 (IIS)”、“Web 服务器”和“安全性”,然后选择“请求筛选”。 单击 “下一步” 。
。 - 在“选择功能”页上,单击“下一步”。
 - 在“确认安装选择”页上,单击“安装”。
 - 在“结果” 页面中单击“关闭” 。
 
Windows 8 或 Windows 8.1
- 在“开始”屏幕上,将指针一直移动到左下角,右键单击“开始”按钮,然后单击“控制面板”。
 - 在“控制面板”中,单击“程序与功能”,然后单击“打开或关闭 Windows 功能”。
 - 依次展开“Internet 信息服务”、“万维网服务”和“安全性”,然后选择“请求筛选”。

 - 单击“确定”。
 - 单击“关闭” 。
 
Windows Server 2008 或 Windows Server 2008 R2
- 在任务栏上,单击“开始”,指向“管理工具”,然后单击“服务器管理器”。
 - 在“服务器管理器”层次结构窗格中,展开“角色”,然后单击“Web 服务器(IIS)”。
 - 在“Web 服务器(IIS)”窗格中,滚动到“角色服务”部分,然后单击“添加角色服务”。
 - 在“添加角色服务向导”的“选择角色服务”页上,选择“请求筛选”,然后单击“下一步”。

 - 在“确认安装选择”页中,单击“安装”。
 - 在“结果” 页面中单击“关闭” 。
 
Windows Vista 或 Windows 7
- 在任务栏上,单击“开始”,然后单击“控制面板”。
 - 在“控制面板”中,单击“程序与功能”,然后单击“打开或关闭 Windows 功能”。
 - 扩展“Internet Information Services”,展开“万维网服务”,然后展开“安全性”。
 - 选择“请求筛选”,然后单击“确定”。

 
操作方式
IIS 7.0 用户请注意:本节中的某些步骤可能需要安装 Microsoft Administration Pack for IIS 7.0,其中包括请求筛选用户界面。 若要安装 Microsoft Administration Pack for IIS 7.0,请参阅以下 URL:
如何添加隐藏段
打开 Internet Information Services (IIS) 管理器:
如果使用的是 Windows Server 2012 或 Windows Server 2012 R2:
- 在任务栏上,单击“服务器管理器”,单击“工具”,然后单击“Internet Information Services (IIS)管理器”。
 
如果使用的是 Windows 8 或 Windows 8.1:
- 按住 Windows 键,按字母 X,然后单击“控制面板”。
 - 单击“管理工具”,然后双击“Internet 信息服务(IIS)管理器”。
 
如果使用的是 Windows Server 2008 或 Windows Server 2008 R2:
- 在任务栏上,单击“开始”,指向“管理工具”,然后单击“Internet Information Services (IIS)管理器”。
 
如果使用的是 Windows Vista 或 Windows 7:
- 在任务栏上,单击“开始”,然后单击“控制面板”。
 - 双击“管理工具”,然后双击“Internet 信息服务(IIS)管理器”。
 
在“连接”窗格中,转到要为其修改请求筛选设置的连接、站点、应用程序或目录。
配置
特性
| 属性 | 说明 | 
|---|---|
segment | 
必需的字符串属性。  指定不应提供给客户端的文件系统部分。 有关默认值的完整列表,请参阅本主题后面的“默认配置”部分。  | 
子元素
无。
配置示例
以下示例 Web.config 文件将配置两个选项:它将配置 IIS 以拒绝对“_private”文件夹的请求访问,并将配置请求筛选以允许 WebDAV 访问隐藏段。
<configuration>
   <system.webServer>
      <security>
         <requestFiltering>
            <hiddenSegments applyToWebDAV="false">
               <add segment="_private" />
            </hiddenSegments>
         </requestFiltering>
      </security>
   </system.webServer>
</configuration>
代码示例
以下代码示例将配置两个选项:它们将配置 IIS 以拒绝对对“默认网站”中“_private”文件夹的请求访问,并将配置请求筛选以允许 WebDAV 访问隐藏段。
AppCmd.exe
appcmd.exe set config "Default Web Site" -section:system.webServer/security/requestFiltering /hiddenSegments.applyToWebDAV:"False"
appcmd.exe set config "Default Web Site" -section:system.webServer/security/requestFiltering /+"hiddenSegments.[segment='_private']"
PowerShell
$hiddenSegments = Get-IISConfigSection -CommitPath 'Default Web Site' -SectionPath 'system.webServer/security/requestFiltering' | Get-IISConfigElement -ChildElementName 'hiddenSegments'
Set-IISConfigAttributeValue -ConfigElement $hiddenSegments -AttributeName 'applyToWebDAV' -AttributeValue $false
$hiddenSegments = Get-IISConfigSection -CommitPath 'Default Web Site' -SectionPath 'system.webServer/security/requestFiltering' | Get-IISConfigCollection -CollectionName 'hiddenSegments'
New-IISConfigCollectionElement -ConfigCollection $hiddenSegments -ConfigAttribute @{ 'segment' = '_private' }
C#
using System;
using System.Text;
using Microsoft.Web.Administration;
internal static class Sample
{
   private static void Main()
   {
      using (ServerManager serverManager = new ServerManager())
      {
         Configuration config = serverManager.GetWebConfiguration("Default Web Site");
         ConfigurationSection requestFilteringSection = config.GetSection("system.webServer/security/requestFiltering");
         ConfigurationElement hiddenSegmentsElement = requestFilteringSection.GetChildElement("hiddenSegments");
         hiddenSegmentsElement["applyToWebDAV"] = false;
         ConfigurationElementCollection hiddenSegmentsCollection = hiddenSegmentsElement.GetCollection();
         ConfigurationElement addElement = hiddenSegmentsCollection.CreateElement("add");
         addElement["segment"] = @"_private";
         hiddenSegmentsCollection.Add(addElement);
         serverManager.CommitChanges();
      }
   }
}
VB.NET
Imports System
Imports System.Text
Imports Microsoft.Web.Administration
Module Sample
   Sub Main()
      Dim serverManager As ServerManager = New ServerManager
      Dim config As Configuration = serverManager.GetWebConfiguration("Default Web Site")
      Dim requestFilteringSection As ConfigurationSection = config.GetSection("system.webServer/security/requestFiltering")
      Dim hiddenSegmentsElement As ConfigurationElement = requestFilteringSection.GetChildElement("hiddenSegments")
      hiddenSegmentsElement("applyToWebDAV") = False
      Dim hiddenSegmentsCollection As ConfigurationElementCollection = hiddenSegmentsElement.GetCollection
      Dim addElement As ConfigurationElement = hiddenSegmentsCollection.CreateElement("add")
      addElement("segment") = "_private"
      hiddenSegmentsCollection.Add(addElement)
      serverManager.CommitChanges()
   End Sub
End Module
JavaScript
var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Default Web Site";
var requestFilteringSection = adminManager.GetAdminSection("system.webServer/security/requestFiltering", "MACHINE/WEBROOT/APPHOST/Default Web Site");
var hiddenSegmentsElement = requestFilteringSection.ChildElements.Item("hiddenSegments");
hiddenSegmentsElement.Properties.Item("applyToWebDAV").Value = false;
var hiddenSegmentsCollection = hiddenSegmentsElement.Collection;
var addElement = hiddenSegmentsCollection.CreateNewElement("add");
addElement.Properties.Item("segment").Value = "_private";
hiddenSegmentsCollection.AddElement(addElement);
adminManager.CommitChanges();
VBScript
Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Default Web Site"
Set requestFilteringSection = adminManager.GetAdminSection("system.webServer/security/requestFiltering", "MACHINE/WEBROOT/APPHOST/Default Web Site")
Set hiddenSegmentsElement = requestFilteringSection.ChildElements.Item("hiddenSegments")
hiddenSegmentsElement.Properties.Item("applyToWebDAV").Value = False
Set hiddenSegmentsCollection = hiddenSegmentsElement.Collection
Set addElement = hiddenSegmentsCollection.CreateNewElement("add")
addElement.Properties.Item("segment").Value = "_private"
hiddenSegmentsCollection.AddElement(addElement)
adminManager.CommitChanges()


