添加管理授权提供程序 <add>

概述

<providers> 元素的 <add> 元素向 Internet Information Services (IIS) 7 的管理授权提供商的集合添加授权提供商。

注意

默认授权提供程序 ConfigurationAuthorizationProvider 使用 IIS Administration.config file 文件来存储 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 <add> 元素在 IIS 7.5 中未进行修改。
IIS 7.0 IIS 7.0 中引入了 <providers> 元素的 <add> 元素。
IIS 6.0 空值

安装

IIS 7 及更高版本的默认安装不包括管理服务角色服务。 若要安装此角色服务,请使用以下步骤。

Windows Server 2012 或 Windows Server 2012 R2

  1. 在任务栏上,单击 “服务器管理器”。

  2. 在“服务器管理器”中,单击“管理”菜单,然后单击“添加角色和功能”。

  3. 在“添加角色和功能”向导中,单击“下一步”。 选择安装类型,然后单击“下一步”。 选择目标服务器,然后单击“下一步”。

  4. 在“服务器角色”页上,展开“Web 服务器(IIS)”,展开“管理工具”,然后选择“管理服务”。 单击 “下一步”
    Screenshot of the Server Roles page. Management Tools is expanded. Management Service is selected and highlighted.

  5. 在“选择功能”页上,单击“下一步”

  6. “确认安装选择”页上,单击“安装”

  7. 在“结果” 页面中单击“关闭”

Windows 8 或 Windows 8.1

  1. 在“开始”屏幕上,将指针一直移动到左下角,右键单击“开始”按钮,然后单击“控制面板”
  2. 在“控制面板”中,单击“程序与功能”,然后单击“打开或关闭 Windows 功能”。
  3. 展开“Internet Information Services”,展开“Web 管理工具”,然后选择“IIS 管理服务”。
    Screenshot of the navigation tree in Programs and Features. The I I S Management Service folder is highlighted and selected.
  4. 单击“确定”。
  5. 单击“关闭” 。

Windows Server 2008 或 Windows Server 2008 R2

  1. 在任务栏上,单击“开始”,指向“管理工具”,然后单击“服务器管理器”。
  2. 在“服务器管理器”层次结构窗格中,展开“角色”,然后单击“Web 服务器 (IIS)”。
  3. 在“Web 服务器 (IIS)”窗格中,滚动到“角色服务”部分,然后单击“添加角色服务”。
  4. 在“添加角色服务向导”的“选择角色服务”页上,选择“管理服务”,然后单击“下一步”。
    Screenshot of the Select Role Services page. This page is found in the Add Role Services Wizard. Management Service is selected and highlighted.
  5. “确认安装选择”页中,单击“安装”
  6. 在“结果” 页面中单击“关闭”

Windows Vista 或 Windows 7

  1. 在任务栏上,单击“开始”,然后单击“控制面板”。
  2. 在“控制面板”中,单击“程序与功能”,然后单击“打开或关闭 Windows 功能”。
  3. 展开“Internet Information Services”,然后展开“Web 管理工具”。
  4. 选择“IIS 管理服务”,然后单击“确定”。
    Screenshot of the I I S Management Service page. Enable remote connections is selected.

操作方式

没有用户界面可以为 IIS 7 配置 <authorization> 元素的 <providers> 元素。 若要通过示例来了解如何以编程方式配置 <authorization> 元素的 <providers> 元素,请参阅本文档的代码示例部分。

配置

特性

属性 说明
name 必需的字符串属性。

指定授权提供程序的名称。
type 必需的字符串属性。

指定身份验证提供程序的托管类型。

子元素

无。

配置示例

安装管理服务角色服务时,在 IIS 7 的 Administration.config 根文件中配置 <authorization> 元素下的以下默认 <providers> 元素。

<authorization defaultProvider="ConfigurationAuthorizationProvider">
   <providers>
      <add name="ConfigurationAuthorizationProvider"
         type="Microsoft.Web.Management.Server.ConfigurationAuthorizationProvider, Microsoft.Web.Management, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
   </providers>
</authorization>

代码示例

注意

本文档中的示例说明如何使用已存储在 .NET 全局程序集缓存 (GAC) 中的托管代码程序集。 在使用这些示例中的代码部署你自己的程序集之前,你需要从 GAC 检索程序集信息。 为此,请按照以下步骤操作:

  • 在 Windows 资源管理器中打开 C:\Windows\assembly 路径,其中 C: 是操作系统驱动器。
  • 找到你的程序集。
  • 右键单击程序集,然后单击“属性”。
  • 复制“区域性”值,例如“Neutral”
  • 复制“版本”号,例如“1.0.0.0”
  • 复制“公钥令牌”值,例如“426f62526f636b73”
  • 单击“取消” 。

下面的代码示例将名为 ContosoAuthorizationProvider 的授权提供程序添加到管理授权提供程序集合中,并将默认授权提供程序设置为 ContosoAuthorizationProvider。

AppCmd.exe

注意

无法使用 AppCmd.exe 配置 <system.webServer/Management> 设置。

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.GetAdministrationConfiguration();

         ConfigurationSection authorizationSection = config.GetSection("system.webServer/management/authorization");
         ConfigurationElementCollection providersCollection = authorizationSection.GetCollection("providers");
         ConfigurationElement addElement = providersCollection.CreateElement("add");
         addElement["name"] = @"ContosoAuthorizationProvider";
         addElement["type"] = @"Contoso.Provider, System.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=426f62526f636b73";
         providersCollection.Add(addElement);
         authorizationSection["defaultProvider"] = "ContosoAuthorizationProvider";

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

      Dim authorizationSection As ConfigurationSection = config.GetSection("system.webServer/management/authorization")
      Dim providersCollection As ConfigurationElementCollection = authorizationSection.GetCollection("providers")
      Dim addElement As ConfigurationElement = providersCollection.CreateElement("add")
      addElement("name") = "ContosoAuthorizationProvider"
      addElement("type") = "Contoso.Provider, System.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=426f62526f636b73"
      providersCollection.Add(addElement)
      authorizationSection("defaultProvider") = "ContosoAuthorizationProvider"

      serverManager.CommitChanges()
   End Sub

End Module

JavaScript

var adminManager = new ActiveXObject("Microsoft.ApplicationHost.WritableAdminManager"); 
adminManager.CommitPath = "MACHINE/WEBROOT"; 
adminManager.SetMetadata("pathMapper", "AdministrationConfig");

var authorizationSection = adminManager.GetAdminSection("system.webServer/management/authorization", "MACHINE/WEBROOT"); 
var providersCollection = authorizationSection.ChildElements.Item("providers").Collection;

var addElement = providersCollection.CreateNewElement("add");
addElement.Properties.Item("name").Value = "ContosoAuthorizationProvider";
addElement.Properties.Item("type").Value = "Contoso.Provider, System.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=426f62526f636b73";
providersCollection.AddElement(addElement);
authorizationSection.Properties.Item("defaultProvider").Value = "ContosoAuthorizationProvider";

adminManager.CommitChanges();

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT"
adminManager.SetMetadata "pathMapper", "AdministrationConfig"

Set authorizationSection = adminManager.GetAdminSection("system.webServer/management/authorization", "MACHINE/WEBROOT")
Set providersCollection = authorizationSection.ChildElements.Item("providers").Collection

Set addElement = providersCollection.CreateNewElement("add")
addElement.Properties.Item("name").Value = "ContosoAuthorizationProvider"
addElement.Properties.Item("type").Value = "Contoso.Provider, System.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=426f62526f636b73"
providersCollection.AddElement(addElement)
authorizationSection.Properties.Item("defaultProvider").Value = "ContosoAuthorizationProvider"

adminManager.CommitChanges()