WebDAV 锁 <locks>

概述

<authoring> 元素的 <locks> 元素定义 WebDAV 模块的锁定行为。 更具体地说,<locks> 元素包含一些属性,这些属性定义是否启用 WebDAV 锁定,使用哪个锁存储,以及在客户端可以保存对服务器文件的更改之前是否需要锁定。

兼容性

版本 说明
IIS 10.0 <locks> 元素在 IIS 10.0 中未进行修改。
IIS 8.5 <locks> 元素在 IIS 8.5 中未进行修改。
IIS 8.0 <locks> 元素在 IIS 8.0 中未进行修改。
IIS 7.5 <authoring> 元素的 <locks> 元素作为 IIS 7.5 的功能提供。
IIS 7.0 <authoring> 元素的 <locks> 元素是在 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 发布”。 单击 “下一步”
    Image of Web Server and Common H T T P Features pane expanded and Web DAV Publishing selected.
  5. 在“选择功能”页上,单击“下一步”
  6. “确认安装选择”页上,单击“安装”
  7. 在“结果” 页面中单击“关闭”

Windows 8 或 Windows 8.1

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

Windows Server 2008 R2

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

Windows 7

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

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 信息服务(IIS)管理器”。
    • 如果使用的是 Windows Server 2008 或 Windows Server 2008 R2:

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

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

  3. 在站点的“主页”窗格中双击“WebDAV 创作规则”
    Image of sites Home pane displaying Web DAV Publishing Rules highlighted.

  4. 当显示“WebDAV 创作规则”页后,单击“操作”页中的“WebDAV 设置”

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

    • 将“允许锁定”设置为“True”
    • 对于“锁存储”,请从下拉列表中选择“webdav_simple_lock”
    • 将“需要锁定以便写入”设置为所需设置
      Image of Web DAV Settings page displaying Web DAV dash simple dash lock chosen from the drop down list.
  6. 完成相关步骤后,单击“操作”窗格中的“应用”。

配置

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

特性

属性 说明
enabled 可选的 Boolean 属性。

如果启用了 WebDAV 锁定,则为 true;否则为 false

默认值为 false
lockStore 可选的字符串属性。

指定要用于 WebDAV 锁定的提供程序的名称。 必须在 <lockStores> 集合中定义此名称。

此属性没有默认值。
requireLockForWriting 可选的 Boolean 属性。

如果 WebDAV 创作需要锁,则为 true;否则为 false。 需要 WebDAV 创作锁有助于防止多源创作环境中的冲突。

默认值为 false

子元素

无。

配置示例

以下示例列出了默认网站的示例 <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 创作不需要锁。

AppCmd.exe

appcmd.exe set config "Default Web Site" -section:system.webServer/webdav/authoring /locks.enabled:"True" /locks.lockStore:"webdav_simple_lock" /locks.requireLockForWriting:"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");

         ConfigurationElement locksElement = authoringSection.GetChildElement("locks");
         locksElement["enabled"] = true;
         locksElement["lockStore"] = @"webdav_simple_lock";
         locksElement["requireLockForWriting"] = 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")

      Dim locksElement As ConfigurationElement = authoringSection.GetChildElement("locks")
      locksElement("enabled") = True
      locksElement("lockStore") = "webdav_simple_lock"
      locksElement("requireLockForWriting") = 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");
var locksElement = authoringSection.ChildElements.Item("locks");
locksElement.Properties.Item("enabled").Value = true;
locksElement.Properties.Item("lockStore").Value = "webdav_simple_lock";
locksElement.Properties.Item("requireLockForWriting").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")
Set locksElement = authoringSection.ChildElements.Item("locks")
locksElement.Properties.Item("enabled").Value = True
locksElement.Properties.Item("lockStore").Value = "webdav_simple_lock"
locksElement.Properties.Item("requireLockForWriting").Value = False

adminManager.CommitChanges()