管理身份验证凭据 <credentials>
概述
<authentication>
元素的 <credentials>
元素指定 IIS 管理器用户帐户的凭据。 IIS 管理器用户可以使用 IIS 管理器连接到服务器管理员为其授权的站点和应用程序。
注意
仅当将默认 ConfigurationAuthenticationProvider 用作身份验证提供程序时,<credentials>
元素才适用。
兼容性
版本 | 说明 |
---|---|
IIS 10.0 | <credentials> 元素在 IIS 10.0 中未进行修改。 |
IIS 8.5 | <credentials> 元素在 IIS 8.5 中未进行修改。 |
IIS 8.0 | <credentials> 元素在 IIS 8.0 中未进行修改。 |
IIS 7.5 | <credentials> 元素在 IIS 7.5 中未进行修改。 |
IIS 7.0 | IIS 7.0 中引入了 <authentication> 元素的 <credentials> 元素。 |
IIS 6.0 | 空值 |
安装
IIS 7 及更高版本的默认安装不包括管理服务角色服务。 若要安装此角色服务,请使用以下步骤。
Windows Server 2012 或 Windows Server 2012 R2
- 在任务栏上,单击 “服务器管理器”。
- 在“服务器管理器”中,单击“管理”菜单,然后单击“添加角色和功能”。
- 在“添加角色和功能”向导中,单击“下一步”。 选择安装类型,然后单击“下一步”。 选择目标服务器,然后单击“下一步”。
- 在“服务器角色”页上,展开“Web 服务器(IIS)”,展开“管理工具”,然后选择“管理服务”。 单击 “下一步” 。
。
- 在“选择功能”页上,单击“下一步”。
- 在“确认安装选择”页上,单击“安装”。
- 在“结果” 页面中单击“关闭” 。
Windows 8 或 Windows 8.1
- 在“开始”屏幕上,将指针一直移动到左下角,右键单击“开始”按钮,然后单击“控制面板”。
- 在“控制面板”中,单击“程序与功能”,然后单击“打开或关闭 Windows 功能”。
- 展开“Internet Information Services”,展开“Web 管理工具”,然后选择“IIS 管理服务”。
- 单击“确定”。
- 单击“关闭” 。
Windows Server 2008 或 Windows Server 2008 R2
- 在任务栏上,单击“开始”,指向“管理工具”,然后单击“服务器管理器”。
- 在“服务器管理器”层次结构窗格中,展开“角色”,然后单击“Web 服务器(IIS)”。
- 在“Web 服务器(IIS)”窗格中,滚动到“角色服务”部分,然后单击“添加角色服务”。
- 在“添加角色服务向导”的“选择角色服务”页上,选择“管理服务”,然后单击“下一步”。
- 在“确认安装选择”页中,单击“安装”。
- 在“结果” 页面中单击“关闭” 。
Windows Vista 或 Windows 7
- 在任务栏上,单击“开始”,然后单击“控制面板”。
- 在“控制面板”中,单击“程序与功能”,然后单击“打开或关闭 Windows 功能”。
- 展开“Internet Information Services”,然后展开“Web 管理工具”。
- 选择“IIS 管理服务”,然后单击“确定”。
操作方式
如何为服务器启用 IIS 管理器凭据
打开 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)管理器”。
在“连接”窗格中,单击服务器名称。
如何将 IIS 管理器用户凭据添加到服务器
打开 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)管理器”。
在“连接”窗格中,单击服务器名称。
配置
特性
无。
子元素
元素 | 说明 |
---|---|
add |
可选元素。 将 IIS 管理器用户帐户添加到 IIS 管理器用户集合中。 |
配置示例
以下配置示例演示如何将名为 ContosoUser 的 IIS 管理器用户添加到 Administration.config。
<credentials>
<add name="ContosoUser" password="Encrypted-Password-Data" enabled="true" />
</credentials>
代码示例
以下代码示例将名为 ContosoUser 的 IIS 管理器用户帐户添加到 IIS 7。
AppCmd.exe
注意
无法使用 AppCmd.exe 配置 <system.webServer/management/authentication>
设置。
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 credentialsCollection = authenticationSection.GetCollection("credentials");
ConfigurationElement addElement = credentialsCollection.CreateElement("add");
addElement["name"] = @"ContosoUser";
addElement["password"] = @"P@ssw0rd";
addElement["enabled"] = true;
credentialsCollection.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.GetAdministrationConfiguration
Dim authenticationSection As ConfigurationSection = config.GetSection("system.webServer/management/authentication")
Dim credentialsCollection As ConfigurationElementCollection = authenticationSection.GetCollection("credentials")
Dim addElement As ConfigurationElement = credentialsCollection.CreateElement("add")
addElement("name") = "ContosoUser"
addElement("password") = "P@ssw0rd"
credentialsCollection.Add(addElement)
addElement("enabled") = True
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 credentialsCollection = authenticationSection.ChildElements.Item("credentials").Collection;
var addElement = credentialsCollection.CreateNewElement("add");
addElement.Properties.Item("name").Value = "ContosoUser";
addElement.Properties.Item("password").Value = "P@ssw0rd";
addElement.Properties.Item("enabled").Value = true;
credentialsCollection.AddElement(addElement);
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 credentialsCollection = authenticationSection.ChildElements.Item("credentials").Collection
Set addElement = credentialsCollection.CreateNewElement("add")
addElement.Properties.Item("name").Value = "ContosoUser"
addElement.Properties.Item("password").Value = "P@ssw0rd"
addElement.Properties.Item("enabled").Value = True
credentialsCollection.AddElement(addElement)
adminManager.CommitChanges()