WebDAV <webdav>

概述

<webdav> 元素包含为 Internet Information Services (IIS) 7 配置 Web 分布式创作和版本管理 (WebDAV) 的设置。 WebDAV 是基于 Internet 的开放标准,支持通过 HTTP 和 HTTPS 连接编辑网站。 与文件传输协议 (FTP) 相比,WebDAV 具有多项优势,最显著的优势是提供更多安全选项,并且可使用单一 TCP 端口进行所有通信。

兼容性

版本 说明
IIS 10.0 <webdav> 元素在 IIS 10.0 中未进行修改。
IIS 8.5 <webdav> 元素在 IIS 8.5 中未进行修改。
IIS 8.0 <webdav> 元素在 IIS 8.0 中未进行修改。
IIS 7.5 <webdav> 元素作为 IIS 7.5 的功能提供。
IIS 7.0 <webdav> 元素是在 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 of the Server Roles page with the WebDAV option being highlighted.
  5. 在“选择功能”页上,单击“下一步”。
  6. 在“确认安装选择”页上,单击“安装”。
  7. 在“结果” 页面中单击“关闭” 。

Windows 8 或 Windows 8.1

  1. 在“开始”屏幕上,将指针一直移动到左下角,右键单击“开始”按钮,然后单击“控制面板”。
  2. 在“控制面板”中,单击“程序与功能”,然后单击“打开或关闭 Windows 功能”。
  3. 依次展开“Internet Information Services”、“万维网服务”和“常见 HTTP 功能”,然后选择“WebDAV 发布”。
    Screenshot of the Windows Features dialog box with a focus on the WebDAV Publishing folder within the Internet Information Services folder.
  4. 单击“确定”。
  5. 单击“关闭” 。

Windows Server 2008 R2

  1. 在任务栏上,单击“开始”,指向“管理工具”,然后单击“服务器管理器”。
  2. 在“服务器管理器”层次结构窗格中,展开“角色”,然后单击“Web 服务器 (IIS)”。
  3. 在“Web 服务器 (IIS)”窗格中,滚动到“角色服务”部分,然后单击“添加角色服务”。
  4. 在“添加角色服务向导”的“选择角色服务”页,展开“常见 HTTP 功能”,选择“WebDAV 发布”,然后单击“下一步”。
    Screenshot of the Add Role Services Wizard with a focus on the WebDAV Publishing option.
  5. 在“确认安装选择”页中,单击“安装”。
  6. 在“结果” 页面中单击“关闭” 。

Windows 7

  1. 在任务栏上,单击“开始”,然后单击“控制面板”。
  2. 在“控制面板”中,单击“程序与功能”,然后单击“打开或关闭 Windows 功能”。
  3. 依次展开“Internet Information Services”、“万维网服务”和“常见 HTTP 功能”。
  4. 选择“WebDAV 发布”,然后单击“确定”。
    Screenshot of the Turn Windows features on or off wizard with a focus on the WebDAV Publishing folder within the World Wide Web Services and Common H T T P folders.

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. 在“连接”窗格中,展开服务器名称,然后转到要在其中启用 WebDAV 发布的站点、应用程序或目录。

  3. 在“主页”窗格中,双击“WebDAV 创作规则”。
    Screenshot of the I I S Manager's Home pane with a focus on the WebDAV Authoring Rules application shortcut.

  4. 在“操作”窗格中,单击“启用 WebDAV”。
    Screenshot of the I I S Manager screen's Actions pane with a focus on the Enable WebDAV option.

注意

启用 WebDAV 发布后,需要先添加创作规则,然后用户或组才能将内容发布到服务器。 有关如何创建创作规则的详细信息,请参阅 authoringRules 主题。


如何添加 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 the Default Web Site Home screen's Home pane with a focus on the WebDAV Authoring Rules shortcut.

  4. 在“操作”窗格中,单击“添加创作规则...”。
    Screenshot of the WebDav Authoring Rules screen's Actions pane with a focus on the Add Authoring Rule option.

  5. 在“添加创作规则”对话框中,指定以下选项:

    • 允许访问:指定创作规则是应用于所有内容类型,还是应用于特定内容,后者需指定要允许的特定内容类型。
    • 允许访问此内容:指定创作规则是应用于所有用户,还是应用于特定组、角色或用户。
    • 权限:指定创作规则是否允许对指定内容类型和用户进行“读取”、“写入”或“源”访问。
      Screenshot of the Add Authoring Rule dialog box.
  6. 单击“确定”。

配置

在 ApplicationHost.config 文件中,可在全局、站点和目录级别配置 <webdav> 元素。 Web.config 文件中的 WebDAV 设置将被忽略。

特性

无。

子元素

元素 说明
authoring 可选元素。

指定 WebDAV 创作的配置设置。
authoringRules 可选元素。

指定 WebDAV 发布的创作规则。 这些规则指定内容类型以及用户或组的创作权限。
globalSettings 可选元素。 指定 WebDAV 模块的全局设置。

配置示例

以下示例列出了默认网站的示例 <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 服务器的示例 <globalSettings> 元素。 此示例定义锁和属性的内置简单提供程序,并为服务器启用 WebDAV 锁。

<system.webServer>
      <webdav>
         <globalSettings>
            <propertyStores>
               <add name="webdav_simple_prop" image="%windir%\system32\inetsrv\webdav_simple_prop.dll" />
            </propertyStores>
            <lockStores>
               <add name="webdav_simple_lock" image="%windir%\system32\inetsrv\webdav_simple_lock.dll" />
            </lockStores>
         </globalSettings>
         <authoring>
            <locks enabled="true" lockStore="webdav_simple_lock" />
         </authoring>
      </webdav>
   </system.webServer>

代码示例

以下示例为默认网站启用 WebDAV 创作,并配置该网站,使 WebDAV 创作不需要 SSL。

AppCmd.exe

appcmd.exe set config "Default Web Site" -section:system.webServer/webdav/authoring /enabled:"True" /requireSsl:"False"  /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");
         authoringSection["enabled"] = true;
         authoringSection["requireSsl"] = false;

         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")
      authoringSection("enabled") = True
      authoringSection("requireSsl") = False

      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");
authoringSection.Properties.Item("enabled").Value = true;
authoringSection.Properties.Item("requireSsl").Value = false;

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")
authoringSection.Properties.Item("enabled").Value = True
authoringSection.Properties.Item("requireSsl").Value = False

adminManager.CommitChanges()

以下示例配置 WebDAV 创作规则,使 WebDAV 客户端可以发布 IIS MIME 映射中未列出的文件,并添加一条向管理员组授予读取、写入和源访问权限的创作规则。

AppCmd.exe

appcmd.exe set config "Default Web Site" -section:system.webServer/webdav/authoringRules /allowNonMimeMapFiles:"True" /commit:apphost

appcmd.exe set config "Default Web Site" -section:system.webServer/webdav/authoringRules /+"[roles='administrators',path='*',access='Read, Write, Source']" /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 authoringRulesSection = config.GetSection("system.webServer/webdav/authoringRules", "Default Web Site");
         authoringRulesSection["allowNonMimeMapFiles"] = true;

         ConfigurationElementCollection authoringRulesCollection = authoringRulesSection.GetCollection();

         ConfigurationElement addElement = authoringRulesCollection.CreateElement("add");
         addElement["roles"] = @"administrators";
         addElement["path"] = @"*";
         addElement["access"] = @"Read, Write, Source";
         authoringRulesCollection.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 authoringRulesSection As ConfigurationSection = config.GetSection("system.webServer/webdav/authoringRules", "Default Web Site")
      authoringRulesSection("allowNonMimeMapFiles") = True

      Dim authoringRulesCollection As ConfigurationElementCollection = authoringRulesSection.GetCollection

      Dim addElement As ConfigurationElement = authoringRulesCollection.CreateElement("add")
      addElement("roles") = "administrators"
      addElement("path") = "*"
      addElement("access") = "Read, Write, Source"
      authoringRulesCollection.Add(addElement)

      serverManager.CommitChanges()
   End Sub
End Module

JavaScript

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

var authoringRulesSection = adminManager.GetAdminSection("system.webServer/webdav/authoringRules", "MACHINE/WEBROOT/APPHOST/Default Web Site");
authoringRulesSection.Properties.Item("allowNonMimeMapFiles").Value = true;

var authoringRulesCollection = authoringRulesSection.Collection;

var addElement = authoringRulesCollection.CreateNewElement("add");
addElement.Properties.Item("roles").Value = "administrators";
addElement.Properties.Item("path").Value = "*";
addElement.Properties.Item("access").Value = "Read, Write, Source";
authoringRulesCollection.AddElement(addElement);

adminManager.CommitChanges();

VBScript

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

Set authoringRulesSection = adminManager.GetAdminSection("system.webServer/webdav/authoringRules", "MACHINE/WEBROOT/APPHOST/Default Web Site")
authoringRulesSection.Properties.Item("allowNonMimeMapFiles").Value = True

Set authoringRulesCollection = authoringRulesSection.Collection

Set addElement = authoringRulesCollection.CreateNewElement("add")
addElement.Properties.Item("roles").Value = "administrators"
addElement.Properties.Item("path").Value = "*"
addElement.Properties.Item("access").Value = "Read, Write, Source"
authoringRulesCollection.AddElement(addElement)

adminManager.CommitChanges()