WebDAV Locks <locks>

Overview

The <locks> element of the <authoring> element defines the locking behavior for the WebDAV module. More specifically, the <locks> element contains attributes that define whether WebDAV locking is enabled, which lock store to use, and whether locking is required before clients can save changes to files for a server.

Compatibility

Version Notes
IIS 10.0 The <locks> element was not modified in IIS 10.0.
IIS 8.5 The <locks> element was not modified in IIS 8.5.
IIS 8.0 The <locks> element was not modified in IIS 8.0.
IIS 7.5 The <locks> element of the <authoring> element ships as a feature of IIS 7.5.
IIS 7.0 The <locks> element of the <authoring> element was introduced in WebDAV 7.0, which was a separate download for IIS 7.0.
IIS 6.0 N/A

Note

The WebDAV 7.0 and WebDAV 7.5 modules shipped out-of-band for IIS 7.0, which required downloading and installing the modules from the following URL:

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

With Windows 7 and Windows Server 2008 R2, the WebDAV 7.5 module ships as a feature for IIS 7.5, so downloading WebDAV is no longer necessary.

Setup

To support WebDAV publishing for your Web server, you must install the WebDAV module. To do so, use the following steps.

Windows Server 2012 or Windows Server 2012 R2

  1. On the taskbar, click Server Manager.
  2. In Server Manager, click the Manage menu, and then click Add Roles and Features.
  3. In the Add Roles and Features wizard, click Next. Select the installation type and click Next. Select the destination server and click Next.
  4. On the Server Roles page, expand Web Server (IIS), expand Web Server, expand Common HTTP Features, and then select WebDAV Publishing. Click Next.
    Image of Web Server and Common H T T P Features pane expanded and Web DAV Publishing selected.
  5. On the Select features page, click Next.
  6. On the Confirm installation selections page, click Install.
  7. On the Results page, click Close.

Windows 8 or Windows 8.1

  1. On the Start screen, move the pointer all the way to the lower left corner, right-click the Start button, and then click Control Panel.
  2. In Control Panel, click Programs and Features, and then click Turn Windows features on or off.
  3. Expand Internet Information Services, expand World Wide Web Services, expand Common HTTP Features, and then select WebDAV Publishing.
    Image of Common H T T P Features pane in Turn Windows Features on or off page expanded with Web DAV Publishing selected.
  4. Click OK.
  5. Click Close.

Windows Server 2008 R2

  1. On the taskbar, click Start, point to Administrative Tools, and then click Server Manager.
  2. In the Server Manager hierarchy pane, expand Roles, and then click Web Server (IIS).
  3. In the Web Server (IIS) pane, scroll to the Role Services section, and then click Add Role Services.
  4. On the Select Role Services page of the Add Role Services Wizard, expand Common HTTP Features, select WebDAV Publishing, and then click Next.
    Screenshot of Server Manager hierarchy pane with Roles expanded and Web DAV Publishing selected.
  5. On the Confirm Installation Selections page, click Install.
  6. On the Results page, click Close.

Windows 7

  1. On the taskbar, click Start, and then click Control Panel.
  2. In Control Panel, click Programs and Features, and then click Turn Windows Features on or off.
  3. Expand Internet Information Services, then World Wide Web Services, and then Common HTTP Features.
  4. Select WebDAV Publishing, and then click OK.
    Image of World Wide Services and Common H T T P Features pane expanded and Web DAV Publishing selected.

Windows Server 2008 or Windows Vista

How To

How to configure WebDAV locking for a Web site

  1. Open Internet Information Services (IIS) Manager:

    • If you are using Windows Server 2012 or Windows Server 2012 R2:

      • On the taskbar, click Server Manager, click Tools, and then click Internet Information Services (IIS) Manager.
    • If you are using Windows 8 or Windows 8.1:

      • Hold down the Windows key, press the letter X, and then click Control Panel.
      • Click Administrative Tools, and then double-click Internet Information Services (IIS) Manager.
    • If you are using Windows Server 2008 or Windows Server 2008 R2:

      • On the taskbar, click Start, point to Administrative Tools, and then click Internet Information Services (IIS) Manager.
    • If you are using Windows Vista or Windows 7:

      • On the taskbar, click Start, and then click Control Panel.
      • Double-click Administrative Tools, and then double-click Internet Information Services (IIS) Manager.
  2. In the Connections pane, expand the server name, expand the Sites node, then click the name of the site.

  3. In the site's Home pane, double-click WebDAV Authoring Rules.
    Image of sites Home pane displaying Web DAV Publishing Rules highlighted.

  4. When the WebDAV Authoring Rules page is displayed, click WebDAV Settings in the Actions pane.

  5. When the WebDAV Settings page is displayed, specify the following options in the Lock Behavior section:

    • Set Allow Locks to True.
    • For Lock Store, choose webdav_simple_lock from the drop-down list.
    • Set Require Lock for Writing to your desired setting.
      Image of Web DAV Settings page displaying Web DAV dash simple dash lock chosen from the drop down list.
  6. Once you have completed the steps, click Apply in the Actions pane.

Configuration

The <locks> element is configurable only at the site level in the ApplicationHost.config file. Any <locks> elements at other levels or in Web.config files are ignored.

Attributes

Attribute Description
enabled Optional Boolean attribute.

true if WebDAV locking is enabled; otherwise, false.

The default value is false.
lockStore Optional string attribute.

Specifies the name of the provider to use for WebDAV locking. This name must be defined in the <lockStores> collection.

This attribute has no default value.
requireLockForWriting Optional Boolean attribute.

true if locks are required for WebDAV authoring; otherwise, false. Requiring locks for WebDAV authoring helps to prevent collisions in a multi-source authoring environment.

The default value is false.

Child Elements

None.

Configuration Sample

The following example lists a sample <webdav> element for the Default Web Site. This example clears any existing authoring rules, adds a single rule for the administrators group, enables WebDAV authoring, specifies that hidden files are allowed, enables WebDAV locks and specifies the lock provider, and enables WebDAV properties and specifies the default XML namespace for property mapping.

<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>

Sample Code

The following examples enable WebDAV locks for the Default Web Site by using the simple lock provider, and configure the site so that locks are not required for WebDAV authoring.

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

Note

You must be sure to set the commit parameter to apphost when you use AppCmd.exe to configure these settings. This commits the configuration settings to the appropriate location section in the ApplicationHost.config file.

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()