添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

<fileExtensions> 元素包含一组 <add> 元素,这些元素指定 IIS 将允许或拒绝的唯一文件扩展名,具体取决于每个 <add> 元素的定义方式。 通过使用 <fileExtensions> 元素,可以微调服务器将提供给 Web 客户端的内容类型。

例如,如果将 allowUnlisted 属性设置为 false ,则将拒绝下列所有请求:所请求文件的扩展名未包含在允许扩展名列表中。 通过使用 <clear> 元素,可以清除已定义的文件扩展名列表,然后只需指定要允许的文件扩展名。

当请求筛选因文件扩展名被拒绝而阻止 HTTP 请求时,IIS 7 将向客户端返回 HTTP 404 错误,并记录以下 HTTP 唯一子状态,以确定拒绝请求的原因:

IIS 7 及更高版本的默认安装包括请求筛选角色服务或功能。 如果卸载请求筛选角色服务或功能,可以使用以下步骤重新安装它。

Windows Server 2012 或 Windows Server 2012 R2

  • 在任务栏上,单击 “服务器管理器”。
  • 在“服务器管理器 ”中,单击“管理 ”菜单,然后单击“添加角色和功能 ”。
  • 在“添加角色和功能”向导中,单击“下一步” 。 选择安装类型,然后单击“下一步”。 选择目标服务器,然后单击“下一步”。
  • 在“服务器角色”页上,依次展开“Web 服务器 (IIS)”、“Web 服务器”和“安全性”,然后选择“请求筛选”。 单击 “下一步”
  • 在“选择功能” 页上,单击“下一步”
  • “确认安装选择” 页上,单击 “安装”
  • 在“结果” 页面中单击“关闭”
  • Windows 8 或 Windows 8.1

  • 在“开始” 屏幕上,将指针一直移动到左下角,右键单击“开始” 按钮,然后单击“控制面板”
  • 在“控制面板 ”中,单击“程序与功能 ”,然后单击“打开或关闭 Windows 功能 ”。
  • 依次展开“Internet Information Services”、“万维网服务”和“安全性”,然后选择“请求筛选”。
  • 单击“确定”。
  • 单击“关闭” 。
  • 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:

  • https://www.iis.net/expand/AdministrationPack
  • 如何拒绝对特定文件扩展名的访问

  • 打开 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)管理器”。
  • allowUnlisted 可选布尔属性。

    指定 Web 服务器是否应处理具有未列出文件扩展名的文件。 如果将此属性设置为 true ,则必须列出要拒绝的所有文件扩展名。 如果将此属性设置为 false ,则必须列出要允许的所有文件扩展名。

    默认值为 true applyToWebDAV 可选布尔属性。

    指定是否还应将这些设置应用于 WebDAV 请求。

    以下示例 Web.config 文件将配置两个选项。 它将配置请求筛选以允许 WebDAV 访问所有文件扩展名,并将 IIS 配置为拒绝对文件扩展名为 .inc 的文件的访问,这些文件有时被用作应用程序的包含文件。

    <configuration>
       <system.webServer>
          <security>
             <requestFiltering>
                <fileExtensions applyToWebDAV="false">
                   <add fileExtension=".inc" allowed="false" />
                </fileExtensions>
             </requestFiltering>
          </security>
       </system.webServer>
    </configuration>
    

    以下代码示例将向默认网站的文件扩展名列表添加一个条目,该条目将拒绝访问扩展名为 .inc 的所有文件,这些文件有时被用作应用程序的包含文件,它们将配置请求筛选以允许 WebDAV 访问隐藏段。

    若要使用相同的示例来允许访问,请将每个示例中的 allowed 属性的值设置为 true,而不是 false

    AppCmd.exe

    appcmd.exe set config "Default Web Site" -section:system.webServer/security/requestFiltering /fileExtensions.applyToWebDAV:"False"
    appcmd.exe set config "Default Web Site" -section:system.webServer/security/requestFiltering /+"fileExtensions.[fileExtension='.inc',allowed='False']"
    

    PowerShell

    Start-IISCommitDelay
    $fileExtensions = Get-IISConfigSection -CommitPath 'Default Web Site' -SectionPath 'system.webServer/security/requestFiltering' | Get-IISConfigCollection -CollectionName 'fileExtensions'
    New-IISConfigCollectionElement -ConfigCollection $fileExtensions -ConfigAttribute @{ 'fileExtension' = '.inc'; 'allowed' = $false } -AddAt 0
    Set-IISConfigAttributeValue -ConfigElement $fileExtensions -AttributeName 'applyToWebDAV' -AttributeValue $false
    Stop-IISCommitDelay
    
    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 fileExtensionsElement = requestFilteringSection.GetChildElement("fileExtensions");
             fileExtensionsElement["applyToWebDAV"] = false;
             ConfigurationElementCollection fileExtensionsCollection = fileExtensionsElement.GetCollection();
             ConfigurationElement addElement = fileExtensionsCollection.CreateElement("add");
             addElement["fileExtension"] = @"inc";
             addElement["allowed"] = false;
             fileExtensionsCollection.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 fileExtensionsElement As ConfigurationElement = requestFilteringSection.GetChildElement("fileExtensions")
          fileExtensionsElement("applyToWebDAV") = False
          Dim fileExtensionsCollection As ConfigurationElementCollection = fileExtensionsElement.GetCollection
          Dim addElement As ConfigurationElement = fileExtensionsCollection.CreateElement("add")
          addElement("fileExtension") = "inc"
          addElement("allowed") = False
          fileExtensionsCollection.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 fileExtensionsElement = requestFilteringSection.ChildElements.Item("fileExtensions");
    fileExtensionsElement.Properties.Item("applyToWebDAV").Value = false;
    var fileExtensionsCollection = fileExtensionsElement.Collection;
    var addElement = fileExtensionsCollection.CreateNewElement("add");
    addElement.Properties.Item("fileExtension").Value = "inc";
    addElement.Properties.Item("allowed").Value = false;
    fileExtensionsCollection.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 fileExtensionsElement = requestFilteringSection.ChildElements.Item("fileExtensions")
    fileExtensionsElement.Properties.Item("applyToWebDAV").Value = False
    Set fileExtensionsCollection = fileExtensionsElement.Collection
    Set addElement = fileExtensionsCollection.CreateNewElement("add")
    addElement.Properties.Item("fileExtension").Value = "inc"
    addElement.Properties.Item("allowed").Value = False
    fileExtensionsCollection.AddElement(addElement)
    adminManager.CommitChanges()