WebDAV 属性 <properties>

概述

<authoring> 元素的 <properties> 元素定义 WebDAV 模块的锁定行为。 更具体地说,<properties> 元素包含了若干属性,这些属性定义了是否启用自定义 WebDAV、是否允许匿名或无限属性请求的属性,并且可能包含一系列用于定义 XML 命名空间到属性存储提供程序的映射的 <add> 元素。

注意

WebDAV 定义了两种类型的属性:

  • 活属性:这些属性存在于基础文件系统中。 例如,文件名和文件大小。 始终支持这些属性。
  • 死属性:这些属性是用户定义的,存储在属性存储中。 例如,文档的作者或所使用的模板。

若要使用“dead”属性,必须将 <properties> 元素的 allowCustomProperties 设置为 true,并根据 <propertyStores> 集合中定义的属性提供程序列表来定义 XML 命名空间到属性提供程序的映射。

兼容性

版本 说明
IIS 10.0 <properties> 元素在 IIS 10.0 中未进行修改。
IIS 8.5 <properties> 元素在 IIS 8.5 中未进行修改。
IIS 8.0 <properties> 元素在 IIS 8.0 中未进行修改。
IIS 7.5 <authoring> 元素的 <properties> 元素作为 IIS 7.5 的功能提供。
IIS 7.0 <authoring> 元素的 <properties> 元素是在 IIS 7.0 的独立下载项 WebDAV 7.0 中引入的。
IIS 6.0 空值

注意

WebDAV 7.0 和 WebDAV 7.5 模块是 IIS 7.0 带外提供的,需要从以下 URL 下载和安装模块:

https://www.iis.net/expand/WebDAV

在 Windows 7 和 Windows Server 2008 R2 中,WebDAV 7.5 模块作为 IIS 7.5 的功能提供,因此无需再下载 WebDAV。

安装

若要支持 Web 服务器的 WebDAV 发布,必须安装 WebDAV 模块。 为此,请按照以下步骤操作。

Windows Server 2012 或 Windows Server 2012 R2

  1. 在任务栏上,单击 “服务器管理器”。
  2. 在“服务器管理器”中,单击“管理”菜单,然后单击“添加角色和功能”。
  3. 在“添加角色和功能”向导中,单击“下一步”。 选择安装类型,然后单击“下一步”。 选择目标服务器,然后单击“下一步”。
  4. 在“服务器角色”页,展开“Web 服务器 (IIS)”,展开“Web 服务器”,展开“常见 HTTP 功能”,然后选择“WebDAV 发布”。 单击 “下一步”
    Screenshot shows Web Server and Common H T T P Features nodes expanded with Web DAV Publishing selected. .
  5. 在“选择功能”页上,单击“下一步”
  6. “确认安装选择”页上,单击“安装”
  7. 在“结果” 页面中单击“关闭”

Windows 8 或 Windows 8.1

  1. 在“开始”屏幕上,将指针一直移动到左下角,右键单击“开始”按钮,然后单击“控制面板”
  2. 在“控制面板”中,单击“程序与功能”,然后单击“打开或关闭 Windows 功能”。
  3. 依次展开“Internet Information Services”、“万维网服务”和“常见 HTTP 功能”,然后选择“WebDAV 发布”。
    Screenshot shows Turn Windows features on or off page with Common H T T P Features node expanded and Web DAV Publishing selected.
  4. 单击“确定”。
  5. 单击“关闭” 。

Windows Server 2008 R2

  1. 在任务栏上,单击“开始”,指向“管理工具”,然后单击“服务器管理器”。
  2. 在“服务器管理器”层次结构窗格中,展开“角色”,然后单击“Web 服务器(IIS)”。
  3. 在“Web 服务器 (IIS)”窗格中,滚动到“角色服务”部分,然后单击“添加角色服务”。
  4. 在“添加角色服务向导”的“选择角色服务”页,展开“常见 HTTP 功能”,选择“WebDAV 发布”,然后单击“下一步”。
    Screenshot of Select Role Services page showing Common H T T P Features node expanded and Web DAV Publishing selected.
  5. “确认安装选择”页中,单击“安装”
  6. 在“结果” 页面中单击“关闭”

Windows 7

  1. 在任务栏上,单击“开始”,然后单击“控制面板”。
  2. 在“控制面板”中,单击“程序与功能”,然后单击“打开或关闭 Windows 功能”。
  3. 依次展开“Internet Information Services”、“万维网服务”和“常见 HTTP 功能”
  4. 选择“WebDAV 发布”,然后单击“确定”。
    Screenshot displays Common H T T P Features node expanded with Web DAV Publishing highlighted.

Windows Server 2008 或 Windows Vista

操作方式

如何为网站配置 WebDAV 属性

  1. 打开 Internet Information Services (IIS) 管理器:

    • 如果使用的是 Windows Server 2012 或 Windows Server 2012 R2:

      • 在任务栏上,单击“服务器管理器”,单击“工具”,然后单击“Internet Information Services (IIS)管理器”
    • 如果使用的是 Windows 8 或 Windows 8.1:

      • 按住 Windows 键,按字母 X,然后单击“控制面板”。
      • 单击“管理工具”,然后双击“Internet Information Services (IIS) 管理器”。
    • 如果使用的是 Windows Server 2008 或 Windows Server 2008 R2:

      • 在任务栏上,单击“开始”,指向“管理工具”,然后单击“Internet Information Services (IIS)管理器”
    • 如果使用的是 Windows Vista 或 Windows 7:

      • 在任务栏上,单击“开始”,然后单击“控制面板”。
      • 双击“管理工具”,然后双击“Internet Information Services (IIS) 管理器”。
  2. 在“连接”窗格中,展开服务器名称,展开“站点”节点,然后单击站点名称

  3. 在站点的“主页”窗格中双击“WebDAV 创作规则”
    Screenshot of Home pane showing Web DAV Authoring Rules selected.

  4. 当显示“WebDAV 创作规则”页后,单击“操作”页中的“WebDAV 设置”
    Screenshot of Web DAV Authoring Rules page with Web DAV Settings displayed in the Actions pane.

  5. 显示“WebDAV 设置”页后,请在“属性行为”部分指定以下选项

    • 将“允许匿名属性查询”设置为 False

    • 将“允许自定义属性”设置为 True

    • 将“允许深度不受限制的属性查询”设置为 False。

      Screenshot of Web DAV Settings page with Property Behavior section.

  6. 单击省略号 (...) 按钮启动命名空间集合编辑器
    Screenshot of Name space Collection Editor dialog box showing web dav dash simple dash prop selected from the drop down list.

  7. 单击“添加”,然后从下拉列表中选择“webdav_simple_prop”

  8. 为 XmlNameSpace 指定“*”,然后单击“确定”

  9. 完成上述步骤后,单击“操作”窗格中的“应用”

配置

<properties> 元素只能在 ApplicationHost.config 文件中的服务器级别进行配置。 如果 <properties> 元素是在其他级别定义的,或是包含在 Web.config 文件中,则将被忽略。

特性

属性 说明
allowAnonymousPropfind 可选的 Boolean 属性。 如果允许匿名 WebDAV 属性请求,则为 true;否则为 false。 重要说明:大多数 WebDAV 谓词都需要身份验证;但为了向后兼容某些 WebDAV 客户端,可能允许匿名 WebDAV 属性请求。 除非环境有特定要求,否则应始终禁用匿名 WebDAV 属性请求,因为此类请求可能会导致网站信息泄漏。 例如,匿名 WebDAV 客户端可以检索应用程序中的文件列表。 默认值为 false
allowInfinitePropfindDepth 可选的 Boolean 属性。

如果允许无限深度 WebDAV 属性请求,则为 true;否则为 false

重要说明:由于满足无限深度 WebDAV 属性请求需要巨大的 CPU 时间资源,因此强烈建议不要允许无限深度 WebDAV 属性请求。 此类请求甚至可能导致应用程序拒绝服务。 除非环境有特定要求,否则应始终禁用无限深度 WebDAV 属性请求。

默认值为 false
allowCustomProperties 可选的 Boolean 属性。

如果允许自定义 WebDAV 属性,则为 true;否则为 false

注意:自定义 WebDAV 属性也称为“死”属性。

注意:如果 allowCustomProperties 设置为 true 但未定义任何属性存储,或者没有用于属性存储映射的 XML 命名空间,则无法存储任何自定义属性。

默认值为 true

子元素

元素 说明
add 可选元素。

将 XML 命名空间的映射添加到属性提供程序。
clear 可选元素。

清除所有现有命名空间映射。
remove 可选元素。 从 XML 命名空间列表中移除与属性提供程序的映射。

配置示例

以下示例列出了默认网站的示例 <webdav> 元素。 此示例可清除任何现有的创作规则,为管理员组添加单个规则,启用 WebDAV 创作,指定允许隐藏文件,启用 WebDAV 锁并指定锁提供程序,同时启用 WebDAV 属性并指定属性映射的默认 XML 命名空间。

<location path="Default Web Site">
   <system.webServer>
      <webdav>
         <authoringRules defaultAccess="none" allowNonMimeMapFiles="true" defaultMimeType="text/plain">
            <clear />
            <add roles="administrators" path="*" access="Read, Write, Source" />
         </authoringRules>
         <authoring enabled="true" requireSsl="false">
            <fileSystem allowHiddenFiles="true" />
            <locks enabled="true" lockStore="webdav_simple_lock" requireLockForWriting="false" />
            <properties allowAnonymousPropfind="false" allowInfinitePropfindDepth="false" allowCustomProperties="true">
               <clear />
               <add xmlNamespace="*" propertyStore="webdav_simple_prop" />
            </properties>
         </authoring>
      </webdav>
   </system.webServer>
</location>

代码示例

以下示例将配置 WebDAV 属性设置,以禁用匿名和无限深度属性查询,并使用映射到内置 webdav_simple_prop 提供程序的默认 XML 命名空间来启用自定义属性。

AppCmd.exe

appcmd.exe set config "Default Web Site" -section:system.webServer/webdav/authoring /properties.allowAnonymousPropfind:"False" /commit:apphost

appcmd.exe set config "Default Web Site" -section:system.webServer/webdav/authoring /properties.allowInfinitePropfindDepth:"False" /commit:apphost

appcmd.exe set config "Default Web Site" -section:system.webServer/webdav/authoring /properties.allowCustomProperties:"True" /commit:apphost

appcmd.exe set config "Default Web Site" -section:system.webServer/webdav/authoring /+"properties.[xmlNamespace='*',propertyStore='webdav_simple_prop']" /commit:apphost

注意

使用 AppCmd.exe 配置这些设置时,必须确保将 commit 参数设置为 apphost。 这会将配置设置提交到 ApplicationHost.config 文件中的相应位置部分。

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.GetApplicationHostConfiguration();
         ConfigurationSection authoringSection = config.GetSection("system.webServer/webdav/authoring", "Default Web Site");

         ConfigurationElement propertiesElement = authoringSection.GetChildElement("properties");
         propertiesElement["allowAnonymousPropfind"] = false;
         propertiesElement["allowInfinitePropfindDepth"] = false;
         propertiesElement["allowCustomProperties"] = true;

         ConfigurationElementCollection propertiesCollection = propertiesElement.GetCollection();

         ConfigurationElement addElement = propertiesCollection.CreateElement("add");
         addElement["xmlNamespace"] = @"*";
         addElement["propertyStore"] = @"webdav_simple_prop";
         propertiesCollection.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.GetApplicationHostConfiguration
      Dim authoringSection As ConfigurationSection = config.GetSection("system.webServer/webdav/authoring", "Default Web Site")

      Dim propertiesElement As ConfigurationElement = authoringSection.GetChildElement("properties")
      propertiesElement("allowAnonymousPropfind") = False
      propertiesElement("allowInfinitePropfindDepth") = False
      propertiesElement("allowCustomProperties") = True

      Dim propertiesCollection As ConfigurationElementCollection = propertiesElement.GetCollection

      Dim addElement As ConfigurationElement = propertiesCollection.CreateElement("add")
      addElement("xmlNamespace") = "*"
      addElement("propertyStore") = "webdav_simple_prop"
      propertiesCollection.Add(addElement)

      serverManager.CommitChanges()
   End Sub
End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";

var authoringSection = adminManager.GetAdminSection("system.webServer/webdav/authoring", "MACHINE/WEBROOT/APPHOST/Default Web Site");
var propertiesElement = authoringSection.ChildElements.Item("properties");
propertiesElement.Properties.Item("allowAnonymousPropfind").Value = false;
propertiesElement.Properties.Item("allowInfinitePropfindDepth").Value = false;
propertiesElement.Properties.Item("allowCustomProperties").Value = true;

var propertiesCollection = propertiesElement.Collection;

var addElement = propertiesCollection.CreateNewElement("add");
addElement.Properties.Item("xmlNamespace").Value = "*";
addElement.Properties.Item("propertyStore").Value = "webdav_simple_prop";
propertiesCollection.AddElement(addElement);

adminManager.CommitChanges();

VBScript

Set adminManager = createObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"

Set authoringSection = adminManager.GetAdminSection("system.webServer/webdav/authoring", "MACHINE/WEBROOT/APPHOST/Default Web Site")
Set propertiesElement = authoringSection.ChildElements.Item("properties")
propertiesElement.Properties.Item("allowAnonymousPropfind").Value = False
propertiesElement.Properties.Item("allowInfinitePropfindDepth").Value = False
propertiesElement.Properties.Item("allowCustomProperties").Value = True

Set propertiesCollection = propertiesElement.Collection

Set addElement = propertiesCollection.CreateNewElement("add")
addElement.Properties.Item("xmlNamespace").Value = "*"
addElement.Properties.Item("propertyStore").Value = "webdav_simple_prop"
propertiesCollection.AddElement(addElement)

adminManager.CommitChanges()