WebDAV 创作规则 <authoringRules>

概述

<authoringRules> 元素可以在网站中为每个 URI 定义创作规则,并指定该 URI 空间的 WebDAV 创作权限。 此元素中的权限是可继承的,因此子 URI 将具有与父 URI 相同的权限,前提是子 URI 没有定义唯一权限。

该元素包含一系列 <add> 元素,用于定义单个创作规则,这些规则包含特定内容类型的用户或组的访问权限。

WebDAV 创作规则似乎与 <authorization> 元素中的授权设置类似,但它们是单独存储的,以便 IIS 维护两组不同的授权:一组用于常规 HTTP(非 WebDAV)请求,另一组用于 WebDAV 请求。

兼容性

版本 说明
IIS 10.0 <authoringRules> 元素在 IIS 10.0 中未进行修改。
IIS 8.5 <authoringRules> 元素在 IIS 8.5 中未进行修改。
IIS 8.0 <authoringRules> 元素在 IIS 8.0 中未进行修改。
IIS 7.5 <authoringRules> 元素作为 IIS 7.5 的功能提供。
IIS 7.0 <authoringRules> 元素是在 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 that shows Web DAV Publishing selected for Windows Server 2012.
  5. 在“选择功能”页上,单击“下一步”
  6. “确认安装选择”页上,单击“安装”
  7. 在“结果” 页面中单击“关闭”

Windows 8 或 Windows 8.1

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

Windows Server 2008 R2

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

Windows 7

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

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 that shows the Default Web Site Home pane. Web DAV Authoring Rules is selected.

  4. 在“操作”窗格中,单击“添加创作规则...”。
    Screenshot that shows the Web DAV Authoring Rules pane.

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

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

配置

可在 ApplicationHost.config 文件中为每个 URI 配置 <authoringRules> 元素。 设置可以全局存储(在站点级别),也可以按文件夹存储。 无法委托 <authoringRules> 元素,因此将忽略 Web.config 文件中的任何 <authoringRules> 元素。

特性

属性 说明
defaultAccess 可选 flags 属性。

指定 WebDAV 创作的默认访问设置。 这些值通过逻辑 OR 运算进行组合,因此“None, Read”=“Read”。

注意:Source 访问允许 WebDAV 客户端请求脚本映射文件(如 ASP.NET 或 PHP 文件)的内容,而不是文件的处理输出。

默认值为 None

说明
None 不允许创作。

数值为 0
Read 允许读取访问。

数值为 1
Write 允许写入访问。

数值为 2
Source 允许访问源代码。

数值为 16
allowNonMimeMapFiles 可选的 Boolean 属性。 如果对 MIME 映射中未定义的文件应允许 WebDAV 请求,则为 true;否则为 false。 例如,脚本映射的文件在 MIME 映射中未定义,但 Web 作者可能仍需要编辑这些文件,默认情况下 IIS 请求中不允许这些操作。 如果设置为 true,WebDAV 模块将接受 MIME 映射中不包含的文件的请求。 如果设置为 false,模块将要求所有文件必须在 MIME 映射中找到,对于任何与 MIME 列表不匹配的请求,都将返回“404.3 - MIME 映射策略阻止了此请求”错误。 默认值为 false
defaultMimeType 可选的字符串属性。

指定未显式定义 MIME 类型的文件的默认 MIME 类型。

默认值为 application/octet-stream

子元素

元素 说明
add 可选元素。

将创作规则添加到创作规则集合中。
clear 可选元素。

清除创作规则集合。
remove 可选元素。

从创作规则集合中删除创作规则。

配置示例

以下示例列出了默认网站的示例 <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 客户端可以发布 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()