管理身份验证提供程序 <providers>

概述

<authentication> 元素的 <providers> 元素用于指定身份验证提供程序,管理服务 (WMSVC) 使用这些提供程序对那些使用 IIS 管理器以远程方式连接到站点和应用程序的用户进行身份验证。

注意

默认身份验证提供程序 ConfigurationAuthenticationProvider 使用 IIS Administration.config 文件来存储 IIS 管理器的 IIS 管理器用户凭据。

兼容性

版本 说明
IIS 10.0 <providers> 元素在 IIS 10.0 中未进行修改。
IIS 8.5 <providers> 元素在 IIS 8.5 中未进行修改。
IIS 8.0 <providers> 元素在 IIS 8.0 中未进行修改。
IIS 7.5 <providers> 元素在 IIS 7.5 中未进行修改。
IIS 7.0 IIS 7.0 中引入了 <authentication> 元素的 <providers> 元素。
IIS 6.0 空值

安装

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

Windows Server 2012 或 Windows Server 2012 R2

  1. 在任务栏上,单击 “服务器管理器”。
  2. 在“服务器管理器”中,单击“管理”菜单,然后单击“添加角色和功能”。
  3. 在“添加角色和功能”向导中,单击“下一步”。 选择安装类型,然后单击“下一步”。 选择目标服务器,然后单击“下一步”。
  4. 在“服务器角色”页上,展开“Web 服务器(IIS)”,展开“管理工具”,然后选择“管理服务”。 单击 “下一步”
    Screenshot that shows Management Service selected for Windows Server 2012.
  5. 在“选择功能”页上,单击“下一步”
  6. “确认安装选择”页上,单击“安装”
  7. 在“结果” 页面中单击“关闭”

Windows 8 或 Windows 8.1

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

Windows Server 2008 或 Windows Server 2008 R2

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

Windows Vista 或 Windows 7

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

操作方式

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

配置

特性

无。

子元素

元素 说明
add 可选元素。

将提供程序添加到身份验证提供程序集合中。

配置示例

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

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

代码示例

注意

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

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

以下代码示例将名为 ContosoAuthenticationProvider 的身份验证提供程序添加到管理身份验证提供程序集合中,并将默认身份验证提供程序设置为 ContosoAuthenticationProvider。

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 authenticationSection = config.GetSection("system.webServer/management/authentication");
         ConfigurationElementCollection providersCollection = authenticationSection.GetCollection("providers");
         ConfigurationElement addElement = providersCollection.CreateElement("add");
         addElement["name"] = @"ContosoAuthenticationProvider";
         addElement["type"] = @"Contoso.Provider, System.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=426f62526f636b73";
         providersCollection.Add(addElement);
         authenticationSection["defaultProvider"] = "ContosoAuthenticationProvider";

         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 authenticationSection As ConfigurationSection = config.GetSection("system.webServer/management/authentication")
      Dim providersCollection As ConfigurationElementCollection = authenticationSection.GetCollection("providers")
      Dim addElement As ConfigurationElement = providersCollection.CreateElement("add")
      addElement("name") = "ContosoAuthenticationProvider"
      addElement("type") = "Contoso.Provider, System.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=426f62526f636b73"
      providersCollection.Add(addElement)
      authenticationSection("defaultProvider") = "ContosoAuthenticationProvider"

      serverManager.CommitChanges()
   End Sub

End Module

JavaScript

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

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

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

adminManager.CommitChanges();

VBScript

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

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

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

adminManager.CommitChanges()