概述
可以组合使用
注意
为了增强安全性,Windows Vista 和 Windows Server 2008 默认都不会安装 IIS 7。 安装 IIS 7 时,IIS 会自动配置为仅提供静态内容,包括 HTML 和图像文件。 必须手动安装网站和应用程序所需的任何其他角色服务和功能。 这一策略大大减少了 IIS 7 攻击面。
兼容性
版本
说明
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 Information Services (IIS) 管理器”。
如果使用的是 Windows Server 2008 或 Windows Server 2008 R2:
在任务栏上,单击“开始”,指向“管理工具”,然后单击“Internet Information Services (IIS)管理器”。
如果使用的是 Windows Vista 或 Windows 7:
在任务栏上,单击“开始”,然后单击“控制面板”。
双击“管理工具”,然后双击“Internet Information Services (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 Information Services (IIS) 管理器”。
如果使用的是 Windows Server 2008 或 Windows Server 2008 R2:
在任务栏上,单击“开始”,指向“管理工具”,然后单击“Internet Information Services (IIS)管理器”。
如果使用的是 Windows Vista 或 Windows 7:
在任务栏上,单击“开始”,然后单击“控制面板”。
双击“管理工具”,然后双击“Internet Information Services (IIS) 管理器”。
在“连接”窗格中,展开服务器名称,展开“站点”,然后导航到要配置的层次结构窗格中的级别,然后单击网站或 Web 应用程序。
滚动到“主页”窗格中的“安全性”部分,然后双击“身份验证”。
在“身份验证”窗格中,选择“匿名身份验证”,然后在“操作”窗格中单击“编辑...”。
在“编辑匿名身份验证凭据”对话框中,执行以下操作之一:
选择“应用程序池标识”以使用应用程序池的标识集,然后单击“确定”。
单击“设置...”,然后在“设置凭据”对话框中,在“用户名”框中输入帐户的用户名,在“密码”和“确认密码”框中输入帐户的密码,单击“确定”,然后再次单击“确定”。
注意
如果使用此过程,请仅授予新帐户对 IIS 服务器计算机的最低权限。
如何启用基本身份验证和禁用匿名身份验证
打开 Internet Information Services (IIS) 管理器:
如果使用的是 Windows Server 2012 或 Windows Server 2012 R2:
在任务栏上,单击“服务器管理器”,单击“工具”,然后单击“Internet Information Services (IIS)管理器”。
如果使用的是 Windows 8 或 Windows 8.1:
按住 Windows 键,按字母 X,然后单击“控制面板”。
单击“管理工具”,然后双击“Internet Information Services (IIS) 管理器”。
如果使用的是 Windows Server 2008 或 Windows Server 2008 R2:
在任务栏上,单击“开始”,指向“管理工具”,然后单击“Internet Information Services (IIS)管理器”。
如果使用的是 Windows Vista 或 Windows 7:
在任务栏上,单击“开始”,然后单击“控制面板”。
双击“管理工具”,然后双击“Internet Information Services (IIS) 管理器”。
在“连接”窗格中,展开服务器名称,展开“站点”,然后单击要为其启用基本身份验证的站点、应用程序或 Web 服务。
滚动到“主页”窗格中的“安全性”部分,然后双击“身份验证”。
在“身份验证”窗格中,选择“基本身份验证”,然后在“操作”窗格中单击“启用”。
在“身份验证”窗格中,选择“匿名身份验证”,然后在“操作”窗格中单击“禁用”。
如何要求安全套接字层
打开 Internet Information Services (IIS) 管理器:
如果使用的是 Windows Server 2012 或 Windows Server 2012 R2:
在任务栏上,单击“服务器管理器”,单击“工具”,然后单击“Internet Information Services (IIS)管理器”。
如果使用的是 Windows 8 或 Windows 8.1:
按住 Windows 键,按字母 X,然后单击“控制面板”。
单击“管理工具”,然后双击“Internet Information Services (IIS) 管理器”。
如果使用的是 Windows Server 2008 或 Windows Server 2008 R2:
在任务栏上,单击“开始”,指向“管理工具”,然后单击“Internet Information Services (IIS)管理器”。
如果使用的是 Windows Vista 或 Windows 7:
在任务栏上,单击“开始”,然后单击“控制面板”。
双击“管理工具”,然后双击“Internet Information Services (IIS) 管理器”。
在“连接”窗格中,转到要为其配置 SSL 要求的站点、应用程序或目录。 不能在服务器级别配置 SSL。
在“开始”窗格中,双击“SSL 设置”。
在“SSL 设置”窗格中,单击“需要 SSL”。
在“操作”窗格中,单击“应用”。
如何为网站、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 Information Services (IIS) 管理器”。
如果使用的是 Windows Server 2008 或 Windows Server 2008 R2:
在任务栏上,单击“开始”,指向“管理工具”,然后单击“Internet Information Services (IIS)管理器”。
如果使用的是 Windows Vista 或 Windows 7:
在任务栏上,单击“开始”,然后单击“控制面板”。
双击“管理工具”,然后双击“Internet Information Services (IIS) 管理器”。
在“连接”窗格中,展开服务器名称,展开“站点”,然后展开要为其启用 Windows 身份验证的站点、应用程序或 Web 服务。
滚动到“主页”窗格中的“安全性”部分,然后双击“身份验证”。
在“身份验证”窗格中,选择“Windows 身份验证”,然后单击“操作 ”窗格中的“启用”。
配置
配置安全设置时,配置 XML 必须包含
特性
无。
子元素
元素
说明
access
可选元素。指定安全套接字层 (SSL) 的配置设置,例如是否使用客户端证书进行身份验证以及加密强度。
applicationDependencies
可选元素。指定一个应用程序,该应用程序具有一个或多个 CGI 或 ISAPI 扩展限制的依赖项。
authentication
可选元素。指定与身份验证相关的设置。
authorization
可选元素。指定与授权相关的设置。
dynamicIpSecurity
可选元素。指定阻止满足一组条件的任何 IP 地址的动态 IP 限制。
ipSecurity
可选元素。根据 IP 版本 4 地址或 DNS 域名指定访问限制。
isapiCgiRestriction
可选元素。指定可限制允许在服务器上运行哪些 CGI 和 ISAPI 程序的设置。
requestFiltering
可选元素。指定请求筛选的配置设置。
配置示例
以下示例为名为 Contoso 的网站配置身份验证、SSL 和请求筛选设置。
代码示例
以下示例为名为 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()