存储 URL 的处理程序。
语法
class HandlersSection : ConfigurationSectionWithCollection
方法
下表列出了 HandlersSection 类公开的方法。
| 名称 | 说明 |
|---|---|
| 添加 | (继承自 ConfigurationSectionWithCollection。) |
| 清除 | (从 ConfigurationSectionWithCollection 继承。) |
| Get | (从 ConfigurationSectionWithCollection 继承。) |
| GetAllowDefinition | (继承自 ConfigurationSection。) |
| GetAllowLocation | (从 ConfigurationSection 继承。) |
| 删除 | (从 ConfigurationSectionWithCollection 继承。) |
| RevertToParent | (从 ConfigurationSection 继承。) |
| SetAllowDefinition | (从 ConfigurationSection 继承。) |
| SetAllowLocation | (从 ConfigurationSection 继承。) |
属性
下表列出了 HandlersSection 类公开的属性。
| 名称 | 描述 |
|---|---|
AccessPolicy |
一个 sint32,指定处理程序的访问策略。 后文的“注解”部分列出了可能的值。 |
Handlers |
HandlerAction 对象的数组。 |
Location |
(继承自 ConfigurationSection。)一个键属性。 |
Path |
(继承自 ConfigurationSection。)一个键属性。 |
SectionInformation |
(从 ConfigurationSection 继承。) |
子类
此类不包含子类。
注解
此类对应于 ApplicationHost.config 文件中的 <handlers> 节。
下表列出了 AccessPolicy 属性的可能值。 默认值为 1 (Read)。
| 值 | 关键字 | 说明 |
|---|---|---|
| 0 | None |
允许处理程序无任何权限。 |
| 1 | Read |
允许处理程序对文件或文件夹的内容具有读取权限。 注意:此标志在 IIS 6.0 中命为 AccessRead。 |
| 2 | Write |
允许处理程序写入服务器上已启用的目录或更改支持写入的文件的内容。 注意:此标志在 IIS 6.0 中命为 AccessWrite。 |
| 4 | Execute |
无论文件类型如何,都允许处理程序执行文件或文件夹的内容。 注意:此标志在 IIS 6.0 中命为 AccessExecute。 |
| 16 | Source |
如果还设置了 Read 或 Write 标志,则允许处理程序访问脚本源代码。 如果已设置 Read,则处理程序可以读取源代码。 如果已设置 Write,则处理程序可以写入源代码。 如果 Read 和 Write 均未设置,则 Source 标志不可用。 注意:此标志在 IIS 6.0 中命为 AccessSource。 |
| 512 | Script |
允许处理程序执行脚本。 注意:此标志在 IIS 6.0 中命为 AccessScript。 |
| 1024 | NoRemoteWrite |
不允许处理程序远程写入。 拒绝创建或更改文件的远程请求。 如果还设置了 Write 标志,则只有请求是来自于运行 IIS Web 服务器的计算机时,请求才能成功。 注意:此标志在 IIS 6.0 中命为 AccessNoRemoteWrite。 |
| 4096 | NoRemoteRead |
不允许处理程序远程读取。 拒绝查看文件的远程请求。 如果还设置了 Read 标志,则只有请求是来自于运行 IIS Web 服务器的计算机时,请求才能成功。 注意:此标志在 IIS 6.0 中命为 AccessNoRemoteRead。 |
| 8192 | NoRemoteExecute |
不允许处理程序远程执行。 拒绝哪些要执行应用程序的远程请求。 如果还设置了 Execute 标志,则只有请求是来自于运行 IIS Web 服务器的计算机时,请求才能成功。 注意:此标志在 IIS 6.0 中命为 AccessNoRemoteExecute。 |
| 16384 | NoRemoteScript |
不允许处理程序远程执行脚本。 拒绝哪些要执行动态内容的远程请求。 如果还设置了 Script 标志,则只有请求是来自于运行 IIS Web 服务器的计算机时,请求才能成功。 注意:此标志在 IIS 6.0 中命为 AccessNoRemoteScript。 |
示例
以下示例在 <handlers> 节中添加和移除处理程序。
注意
添加或移除配置元素会更改基础配置节,但不更改脚本中表示配置节的对象变量。 为了使更改显示在脚本中,必须在进行更改后对对象变量调用 WMI Refresh_ 方法。 这将使用配置存储中的最新数据更新对象变量。
' ----------------------------------------------------------
' The first example adds a handler to the <handlers> section.
' ----------------------------------------------------------
' Connect to the WMI WebAdministration namespace.
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")
' Get the <handlers> section.
Set oSite = oWebAdmin.Get("Site.Name='Default Web Site'")
oSite.GetSection "HandlersSection", oHandlersSection
' Display the old handler names.
WScript.Echo "---[Old Handler List]---"
Call DisplayHandlers
' Create a new handler.
Set oHandler = oWebAdmin.Get("HandlerAction").SpawnInstance_
oHandler.Name = "NewHandler"
oHandler.Path="*.stm"
oHandler.Verb="GET,POST"
oHandler.Modules="ServerSideIncludeModule"
' Add the handler to the <handlers> section.
oHandlersSection.Add "Handlers", oHandler
' Call the WMI Refresh_ method to update the oHandlersSection object.
oHandlersSection.Refresh_
' Display the new handler names.
WScript.Echo "---[New Handler List]---"
Call DisplayHandlers
' ----------------------------------------------------------------
' The second example removes a handler by using the handler name.
' ----------------------------------------------------------------
' Connect to the WMI WebAdministration namespace.
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")
' Get the <handlers> section.
Set oSite = oWebAdmin.Get("Site.Name='Default Web Site'")
oSite.GetSection "HandlersSection", oHandlersSection
' Display the old handler names.
WScript.Echo "---[Old Handler List]---"
Call DisplayHandlers
' Remove the CGI-exe handler by name.
For Each oHandler In oHandlersSection.Handlers
If oHandler.Name = "CGI-exe" Then
oHandlersSection.Remove "Handlers", oHandler
End If
Next
' Call the WMI Refresh_ method to update the oHandlersSection object.
oHandlersSection.Refresh_
' Display the new list of handler names.
WScript.Echo "---[New Handler List]---"
Call DisplayHandlers
' This is the sub that displays the handler names.
Sub DisplayHandlers
WScript.Echo
For Each oHandler In oHandlersSection.Handlers
WScript.Echo "Handler Name: " & oHandler.Name
Next
End Sub
继承层次结构
ConfigurationSectionWithCollection
HandlersSection
要求
| 类型 | 描述 |
|---|---|
| 客户端 | - Windows Vista 上的 IIS 7.0 - Windows 7 上的 IIS 7.5 - Windows 8 上的 IIS 8.0 - Windows 10 上的 IIS 10.0 |
| 服务器 | - Windows Server 2008 上的 IIS 7.0 - Windows Server 2008 R2 上的 IIS 7.5 - Windows Server 2012 上的 IIS 8.0 - Windows Server 2012 R2 上的 IIS 8.5 - Windows Server 2016 上的 IIS 10.0 |
| 产品 | - IIS 7.0、IIS 7.5、IIS 8.0、IIS 8.5、IIS 10.0 |
| MOF 文件 | WebAdministration.mof |