概述
身份验证是用于验证网站或 Web 应用程序的访问者身份的机制。 通常,执行此操作的方式为向访问者分配用户名和密码或允许访问者匿名访问网站上的公共内容。
身份验证用于确认访问者的身份,而授权则用于来控制访问者对网站或应用程序不同区域的访问权限。
IIS 7 支持匿名身份验证、基本身份验证、客户端证书映射身份验证、摘要式身份验证、IIS 客户端证书映射身份验证以及 Windows 身份验证。 其他身份验证模式可由第三方身份验证模块提供。
安装其中一个身份验证模块后,必须对要使用模块的网站、Web 应用程序或 Web 服务启用所选身份验证模块。
此外,默认情况下,IIS 7 还会为 Windows 启用内核模式身份验证(使用 Kerberos 或 NTLM 身份验证方案)。 内核模式身份验证具有以下优势:
Web 应用程序可以使用低特权帐户运行。
如果使用 Kerberos 身份验证,则可以使用服务器服务主体名称 (SPN) 关联的默认帐户之外的不同帐户。
如果使用内核模式身份验证,则可以在不执行显式 SPN 配置的情况下使用 Windows 身份验证 Kerberos 提供程序。
兼容性
版本
说明
IIS 10.0
IIS 8.5
IIS 8.0
IIS 7.5
IIS 7.0
IIS 6.0
空值
安装
操作方式
如何禁用匿名身份验证
打开 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)管理器”。
在“连接”窗格中,展开服务器名称,展开“站点”,然后转到要配置的层次结构窗格中的级别,然后单击网站或 Web 应用程序。
滚动到“主页”窗格中的“安全性”部分,然后双击“身份验证”。
在“身份验证”窗格中,选择“匿名身份验证”,然后在“操作”窗格中单击“禁用”。
如何从 IUSR 帐户更改匿名身份验证凭据
打开 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)管理器”。
在“连接”窗格中,展开服务器名称,展开“站点”,然后导航到要配置的层次结构窗格中的级别,然后单击网站或 Web 应用程序。
滚动到“主页”窗格中的“安全性”部分,然后双击“身份验证”。
在“身份验证”窗格中,选择“匿名身份验证”,然后在“操作”窗格中单击“编辑...”。
在“编辑匿名身份验证凭据”对话框中,执行以下操作之一:
选择“应用程序池标识”以使用应用程序池的标识集,然后单击“确定”。
单击“设置...”,然后在“设置凭据”对话框中,在“用户名”框中输入帐户的用户名,在“密码”和“确认密码”框中输入帐户的密码,单击“确定”,然后再次单击“确定”。
注意
如果使用此过程,请仅授予新帐户对 IIS 服务器计算机的最低权限。
如何为网站、Web 应用程序或 Web 服务启用 Windows 身份验证
打开 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)管理器”。
在“连接”窗格中,展开服务器名称,展开“站点”,然后展开要为其启用 Windows 身份验证的站点、应用程序或 Web 服务。
滚动到“主页”窗格中的“安全性”部分,然后双击“身份验证”。
在“身份验证”窗格中,选择“Windows 身份验证”,然后单击“操作”窗格中的“启用”。
配置
特性
无。
子元素
元素
说明
anonymousAuthentication
可选元素。指定匿名身份验证的设置。
basicAuthentication
可选元素。指定基本身份验证的设置。
clientCertificateMappingAuthentication
可选元素。 指定使用 Active Directory 的客户端证书映射身份验证的设置。
digestAuthentication
可选元素。指定摘要式身份验证的设置。
iisClientCertificateMappingAuthentication
可选元素。指定使用 IIS 的客户端证书映射身份验证的设置。
windowsAuthentication
可选元素。指定 Windows 身份验证的设置。
配置示例
以下配置示例为名为 Contoso 的站点禁用匿名身份验证,然后为站点启用基本身份验证和 Windows 身份验证。
代码示例
以下示例为名为 Contoso 的站点禁用匿名身份验证,然后为站点启用基本身份验证和 Windows 身份验证。
AppCmd.exe
appcmd.exe set config "Contoso" -section:system.webServer/security/authentication/anonymousAuthentication /enabled:"False" /commit:apphost
appcmd.exe set config "Contoso" -section:system.webServer/security/authentication/basicAuthentication /enabled:"True" /commit:apphost
appcmd.exe set config "Contoso" -section:system.webServer/security/authentication/windowsAuthentication /enabled:"True" /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 anonymousAuthenticationSection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication", "Contoso");
anonymousAuthenticationSection["enabled"] = false;
ConfigurationSection basicAuthenticationSection = config.GetSection("system.webServer/security/authentication/basicAuthentication", "Contoso");
basicAuthenticationSection["enabled"] = true;
ConfigurationSection windowsAuthenticationSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication", "Contoso");
windowsAuthenticationSection["enabled"] = true;
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 anonymousAuthenticationSection As ConfigurationSection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication", "Contoso")
anonymousAuthenticationSection("enabled") = False
Dim basicAuthenticationSection As ConfigurationSection = config.GetSection("system.webServer/security/authentication/basicAuthentication", "Contoso")
basicAuthenticationSection("enabled") = True
Dim windowsAuthenticationSection As ConfigurationSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication", "Contoso")
windowsAuthenticationSection("enabled") = True
serverManager.CommitChanges()
End Sub
End Module
JavaScript
var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var anonymousAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/anonymousAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso");
anonymousAuthenticationSection.Properties.Item("enabled").Value = false;
var basicAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/basicAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso");
basicAuthenticationSection.Properties.Item("enabled").Value = true;
var windowsAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/windowsAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso");
windowsAuthenticationSection.Properties.Item("enabled").Value = true;
adminManager.CommitChanges();
VBScript
Set adminManager = CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set anonymousAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/anonymousAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso")
anonymousAuthenticationSection.Properties.Item("enabled").Value = False
Set basicAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/basicAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso")
basicAuthenticationSection.Properties.Item("enabled").Value = True
Set windowsAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/windowsAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso")
windowsAuthenticationSection.Properties.Item("enabled").Value = True
adminManager.CommitChanges()
trait在英语-中文(简体)词典中的翻译《饥荒联机版》哪天月圆?