添加 WebDAV 锁存储 <add>

概述

WebDAV 模块旨在支持在 webdav/globalSettings/lockStores 集合中定义的多个锁存储提供程序。 一系列 <add> 元素定义 <lockStores> 集合中每个锁提供程序的设置。

注意

目前唯一的属性存储提供程序是 webdav_simple_lock,它将 WebDAV 锁存储在内存中。 由于此提供程序将锁存储在内存中,因此在重新启动 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 <lockStores> 元素的 <add> 元素作为 IIS 7.5 的功能提供。
IIS 7.0 <lockStores> 元素的 <add> 元素是在 WebDAV 7.5 中作为 IIS 7.0 独立下载项的一部分引入的。
IIS 6.0 空值

注意

<lockStores><add> 元素是在 WebDAV 7.0 架构中定义的,但因该版本中未实现 WebDAV 锁而被忽略。

注意

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 Web Server and Common H T P Features pane expanded with Web DAV Publishing selected.
  5. 在“选择功能”页上,单击“下一步”
  6. “确认安装选择”页上,单击“安装”
  7. 在“结果” 页面中单击“关闭”

Windows 8 或 Windows 8.1

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

Windows Server 2008 R2

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

Windows 7

  1. 在任务栏上,单击“开始”,然后单击“控制面板”。
  2. 在“控制面板”中,单击“程序与功能”,然后单击“打开或关闭 Windows 功能”。
  3. 依次展开“Internet Information Services”、“万维网服务”和“常见 HTTP 功能”
  4. 选择“WebDAV 发布”,然后单击“确定”。
    Screenshot of Windows Feature page displaying World Wide Web Services and Common H T T P Features pane expanded with 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 创作规则”
    Screenshot of Server Home control panel with Web DAV Publishing highlighted.

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

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

    • 将“允许锁定”设置为“True”
    • 对于“锁存储”,请从下拉列表中选择“webdav_simple_lock”
    • 将“需要锁定以便写入”设置为所需设置
      Screenshot of Web DAV Settings page with Lock Behavior section displayed.
  6. 完成相关步骤后,单击“操作”窗格中的“应用”。

配置

<lockStores> 元素可在 ApplicationHost.config 文件中在全局级别进行配置。 将忽略站点或应用程序级别或 Web.config 文件中的任何设置。

特性

属性 描述
name 必需的特性。 指定锁存储提供程序的名称。
image 必需的特性。 指定锁存储提供程序的文件系统路径。 注意:在 64 位系统上,路径将为 64 位,而在 32 位系统上,将包含 32 位提供程序的路径,并且将忽略 image32 属性
image32 可选特性。 指定 64 位系统上锁提供程序的 32 位路径。 注意:此属性已添加到 WebDAV 7.5 和 IIS 7.5 中

子元素

无。

配置示例

以下示例列出了 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 时,会使用内置属性和锁提供程序填充 propertyStoreslockStores 集合。 这些提供程序集合目前不可扩展,因此本部分中的代码示例仅供参考。

以下示例将 WebDAV 全局设置配置为在安装 WebDAV 模块时重新添加复制到系统的内置属性和锁提供程序。

AppCmd.exe

appcmd.exe set config -section:system.webServer/webdav/globalSettings /+"propertyStores.[name='webdav_simple_prop',image='%windir%\system32\inetsrv\webdav_simple_prop.dll']" /commit:apphost

appcmd.exe set config -section:system.webServer/webdav/globalSettings /+"lockStores.[name='webdav_simple_lock',image='%windir%\system32\inetsrv\webdav_simple_lock.dll']" /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 globalSettingsSection = config.GetSection("system.webServer/webdav/globalSettings");

         ConfigurationElementCollection propertyStoresCollection = globalSettingsSection.GetCollection("propertyStores");

         ConfigurationElement addElement = propertyStoresCollection.CreateElement("add");
         addElement["name"] = @"webdav_simple_prop";
         addElement["image"] = @"%windir%\system32\inetsrv\webdav_simple_prop.dll";
         propertyStoresCollection.Add(addElement);

         ConfigurationElementCollection lockStoresCollection = globalSettingsSection.GetCollection("lockStores");

         ConfigurationElement addElement1 = lockStoresCollection.CreateElement("add");
         addElement1["name"] = @"webdav_simple_lock";
         addElement1["image"] = @"%windir%\system32\inetsrv\webdav_simple_lock.dll";
         lockStoresCollection.Add(addElement1);

         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 globalSettingsSection As ConfigurationSection = config.GetSection("system.webServer/webdav/globalSettings")

      Dim propertyStoresCollection As ConfigurationElementCollection = globalSettingsSection.GetCollection("propertyStores")

      Dim addElement As ConfigurationElement = propertyStoresCollection.CreateElement("add")
      addElement("name") = "webdav_simple_prop"
      addElement("image") = "%windir%\system32\inetsrv\webdav_simple_prop.dll"
      propertyStoresCollection.Add(addElement)

      Dim lockStoresCollection As ConfigurationElementCollection = globalSettingsSection.GetCollection("lockStores")

      Dim addElement1 As ConfigurationElement = lockStoresCollection.CreateElement("add")
      addElement1("name") = "webdav_simple_lock"
      addElement1("image") = "%windir%\system32\inetsrv\webdav_simple_lock.dll"
      lockStoresCollection.Add(addElement1)

      serverManager.CommitChanges()
   End Sub
End Module

JavaScript

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

var globalSettingsSection = adminManager.GetAdminSection("system.webServer/webdav/globalSettings", "MACHINE/WEBROOT/APPHOST");

var propertyStoresCollection = globalSettingsSection.ChildElements.Item("propertyStores").Collection;

var addElement = propertyStoresCollection.CreateNewElement("add");
addElement.Properties.Item("name").Value = "webdav_simple_prop";
addElement.Properties.Item("image").Value = "%windir%\\system32\\inetsrv\\webdav_simple_prop.dll";
propertyStoresCollection.AddElement(addElement);

var lockStoresCollection = globalSettingsSection.ChildElements.Item("lockStores").Collection;

var addElement1 = lockStoresCollection.CreateNewElement("add");
addElement1.Properties.Item("name").Value = "webdav_simple_lock";
addElement1.Properties.Item("image").Value = "%windir%\\system32\\inetsrv\\webdav_simple_lock.dll";
lockStoresCollection.AddElement(addElement1);

adminManager.CommitChanges();

VBScript

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

Set globalSettingsSection = adminManager.GetAdminSection("system.webServer/webdav/globalSettings", "MACHINE/WEBROOT/APPHOST")

Set propertyStoresCollection = globalSettingsSection.ChildElements.Item("propertyStores").Collection

Set addElement = propertyStoresCollection.CreateNewElement("add")
addElement.Properties.Item("name").Value = "webdav_simple_prop"
addElement.Properties.Item("image").Value = "%windir%\system32\inetsrv\webdav_simple_prop.dll"
propertyStoresCollection.AddElement(addElement)

Set lockStoresCollection = globalSettingsSection.ChildElements.Item("lockStores").Collection

Set addElement1 = lockStoresCollection.CreateNewElement("add")
addElement1.Properties.Item("name").Value = "webdav_simple_lock"
addElement1.Properties.Item("image").Value = "%windir%\system32\inetsrv\webdav_simple_lock.dll"
lockStoresCollection.AddElement(addElement1)

adminManager.CommitChanges()