概觀
<add>集合中的<handlers>元素將處理程序加入網購資訊服務(IIS)7 的 HTTP 處理程序清單中。
Compatibility
| 版本 | 註釋 |
|---|---|
| IIS 10.0 |
<add>該元件在 IIS 10.0 中未被修改。 |
| IIS 8.5 | 該 <add> 單元在IIS 8.5中未被修改。 |
| IIS 8.0 | 該 <add> 元件在 IIS 8.0 中未被修改。 |
| IIS 7.5 | 該 <add> 單元在IIS 7.5中未被修改。 |
| IIS 7.0 |
<add>該集合元素<handlers>於 IIS 7.0 中引入。 |
| IIS 6.0 | N/A |
設定
<add>該收藏的元素<handlers>包含在 IIS 7 的預設安裝中。
操作指南
如何在 IIS 7 應用程式中以整合模式運行時,為 ASP.NET 處理程序建立處理程序映射
開放 網際網路資訊服務(IIS)經理:
如果你正在使用 Windows Server 2012 或 Windows Server 2012 R2:
- 在工作列中,點選 伺服器管理員,點選 工具,然後點選 網際網路資訊服務(IIS)管理員。
如果你使用的是 Windows 8 或 Windows 8.1:
- 長按 Windows 鍵,按下字母 X,然後點選 控制面板。
- 點選 「管理工具」,然後雙擊「 網際網路資訊服務(IIS)管理員」。
如果你使用的是 Windows Server 2008 或 Windows Server 2008 R2:
- 在工作列中,點選 開始,指向 管理工具,然後點選 網際網路資訊服務(IIS)管理員。
如果你使用的是 Windows Vista 或 Windows 7:
- 在工作列點選 開始,然後點選 控制面板。
- 雙擊 「管理工具」,然後雙擊「 網際網路資訊服務(IIS)管理員」。
在 Connections 面板中,點選你想新增原生模組的伺服器連線。
在 主畫面 中,雙擊「 處理器映射」。
在 動作 選單中,點選 新增管理處理程序...
在 「新增受管理處理器 」對話框中,請指定以下內容:
請求路徑。 檔案名稱或副檔名來映射。
打字。 管理處理器的型別(類別)名稱。 如果處理器是在應用程式的app_code或 bin 資料夾中定義的,其類型名稱會出現在下拉選單中。
名稱. 一個描述性的名字。
點擊 確定 以關閉 新增管理處理器 對話框。
如何建立 FastCGI 處理器映射
開放 網際網路資訊服務(IIS)經理:
如果你正在使用 Windows Server 2012 或 Windows Server 2012 R2:
- 在工作列中,點選 伺服器管理員,點選 工具,然後點選 網際網路資訊服務(IIS)管理員。
如果你使用的是 Windows 8 或 Windows 8.1:
- 長按 Windows 鍵,按下字母 X,然後點選 控制面板。
- 點選 「管理工具」,然後雙擊「 網際網路資訊服務(IIS)管理員」。
如果你使用的是 Windows Server 2008 或 Windows Server 2008 R2:
- 在工作列中,點選 開始,指向 管理工具,然後點選 網際網路資訊服務(IIS)管理員。
如果你使用的是 Windows Vista 或 Windows 7:
- 在工作列點選 開始,然後點選 控制面板。
- 雙擊 「管理工具」,然後雙擊「 網際網路資訊服務(IIS)管理員」。
在 連接 面板中,點選你想設定 FastCGI 處理器映射的伺服器名稱。
在 主畫面 中,雙擊「 處理器映射」。
在 動作 面板中,點選 新增模組映射...
備註
接下來的步驟要順利進行,你必須已經安裝了執行你指定的檔案路徑或副檔名的二進位檔。 此範例使用了 Microsoft 官網提供的 PHP 實作。
在請求路徑框輸入副檔名,例如 as.php,在模組下拉選單點選 FastCGIModule,在執行檔框輸入腳本引擎的路徑(此例為 PHP-CGI.exe),然後點擊確定。
在 「新增模組映射 」對話框中,點選 「是」。
設定
Attributes
| Attribute | Description | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
allowPathInfo |
選擇性的 Boolean 屬性。 指定處理器是否處理完整路徑資訊,如 contoso/marketing/imageGallery.aspx。 如果值為 真,處理器會處理完整路徑,包括 contoso/marketing/imageGallery。 若值 為假,處理器只會處理路徑的最後一段 /imageGallery。 預設值是 false。 |
||||||||||||||
modules |
選擇性字串屬性。 指定你想將檔案名稱或檔名(副檔名)映射到的模組名稱。 如果你指定多個值,請用逗號(,)分隔。 預設值是 ManagedPipelineHandler。 |
||||||||||||||
name |
必要的字串屬性。 指定處理者映射的唯一名稱。 |
||||||||||||||
path |
必要的字串屬性。 指定處理程序映射所適用的檔名或副檔名。 |
||||||||||||||
preCondition |
選擇性字串屬性。 規定處理員在何種條件下會運行。 preCondition 屬性可以是以下一個或多個可能的值。 如果你指定多個值,請用逗號(,)分隔。
|
||||||||||||||
requireAccess |
可選的列舉屬性。 指定處理器執行的存取層級。 requireAccess 屬性可以是以下一個或多個可能的值。 如果你指定多個值,請用逗號(,)分隔。 預設值是 Script。 註: 即使處理器的 requireAccess 值與目前 accessPolicy 等級不符,它仍是配置中的處理器集合的一部分,並可被初始化,但不會執行。
|
||||||||||||||
resourceType |
選擇性字串屬性。 指定處理者映射所適用的資源類型。 resourceType 屬性可以是以下可能的值之一。 預設值是 Unspecified。
|
||||||||||||||
responseBufferLimit |
可選的 uint 屬性。 指定請求處理程序的回應緩衝區最大大小(以位元組為單位)。 預設值是位 4194304 元組。 |
||||||||||||||
scriptProcessor |
選擇性字串屬性。 指定處理請求的 ISAPI 副名 .dll 檔案或通用閘道介面(CGI).exe 檔案的物理路徑。 scriptProcessor 屬性僅用於腳本映射處理程序的映射。 當你將處理器映射到 ISAPI 擴充功能時,必須為 modules 屬性指定 ISAPIModule。 當你將處理器映射到 CGI 檔案時,必須為模組屬性指定 CGIModule。 |
||||||||||||||
type |
選擇性字串屬性。 指定受管理處理程序的命名空間路徑。 型態屬性僅對受管理處理程序必要。 |
||||||||||||||
verb |
必要的字串屬性。 指定處理者映射所適用的 HTTP 動詞。 |
子專案
沒有。
組態範例
以下範例包含兩個 <add> 定義處理器映射的元素。 第一個 <add> 元素定義了 IIS 7 整合模式下執行的網頁應用程式的 SampleHandler 處理器。 如果你將處理程序組件加入網頁應用程式的 app_code 目錄,則不需要在 type 屬性的值中包含組合名稱。 第二個 <add> 元素定義了使用 FastCGI 模組的 PHP 請求的映射。
<handlers>
<add name="SampleHandler" verb="*"
path="SampleHandler.new"
type="SampleHandler, SampleHandlerAssembly"
resourceType="Unspecified" />
<add name="PHP-FastCGI" verb="*"
path="*.php"
modules="FastCgiModule"
scriptProcessor="c:\php\php-cgi.exe"
resourceType="Either" />
</handlers>
範例程式碼
以下範例為 PHP 模組新增 FastCGI 映射,並在 Contoso 網站上新增處理 PHP 請求的處理器。
AppCmd.exe
appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='c:\php\php-cgi.exe']" /commit:apphost
appcmd.exe set config "Contoso" -section:system.webServer/handlers /+"[name='PHP-FastCGI',path='*.php',verb='GET,HEAD,POST',modules='FastCgiModule',scriptProcessor='c:\php\php-cgi.exe',resourceType='Either']"
備註
第二個範例展示了如何為特定網址新增一個名為 SampleHandler.new 的新 ASP.NET 處理器映射,以支援網頁應用程式。
appcmd.exe set config /section:system.webServer/handlers /+[name=SampleHandler',path='SampleHandler.new',verb='*',type='SampleHandler']
C#
using System;
using System.Text;
using Microsoft.Web.Administration;
internal static class Sample
{
private static void Main()
{
using (ServerManager serverManager = new ServerManager())
{
Configuration appHostConfig = serverManager.GetApplicationHostConfiguration();
ConfigurationSection fastCgiSection = appHostConfig.GetSection("system.webServer/fastCgi");
ConfigurationElementCollection fastCgiCollection = fastCgiSection.GetCollection();
ConfigurationElement applicationElement = fastCgiCollection.CreateElement("application");
applicationElement["fullPath"] = @"c:\php\php-cgi.exe";
fastCgiCollection.Add(applicationElement);
Configuration webConfig = serverManager.GetWebConfiguration("Contoso");
ConfigurationSection handlersSection = webConfig.GetSection("system.webServer/handlers");
ConfigurationElementCollection handlersCollection = handlersSection.GetCollection();
ConfigurationElement addElement = handlersCollection.CreateElement("add");
addElement["name"] = @"PHP-FastCGI";
addElement["path"] = @"*.php";
addElement["verb"] = @"GET,HEAD,POST";
addElement["modules"] = @"FastCgiModule";
addElement["scriptProcessor"] = @"c:\php\php-cgi.exe";
addElement["resourceType"] = @"Either";
handlersCollection.AddAt(0, 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 appHostConfig As Configuration = serverManager.GetApplicationHostConfiguration
Dim fastCgiSection As ConfigurationSection = appHostConfig.GetSection("system.webServer/fastCgi")
Dim fastCgiCollection As ConfigurationElementCollection = fastCgiSection.GetCollection
Dim applicationElement As ConfigurationElement = fastCgiCollection.CreateElement("application")
applicationElement("fullPath") = "c:\php\php-cgi.exe"
fastCgiCollection.Add(applicationElement)
Dim webConfig As Configuration = serverManager.GetWebConfiguration("Contoso")
Dim handlersSection As ConfigurationSection = webConfig.GetSection("system.webServer/handlers")
Dim handlersCollection As ConfigurationElementCollection = handlersSection.GetCollection
Dim addElement As ConfigurationElement = handlersCollection.CreateElement("add")
addElement("name") = "PHP-FastCGI"
addElement("path") = "*.php"
addElement("verb") = "GET,HEAD,POST"
addElement("modules") = "FastCgiModule"
addElement("scriptProcessor") = "c:\php\php-cgi.exe"
addElement("resourceType") = "Either"
handlersCollection.AddAt(0, addElement)
serverManager.CommitChanges()
End Sub
End Module
JavaScript
var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var fastCgiSection = adminManager.GetAdminSection("system.webServer/fastCgi", "MACHINE/WEBROOT/APPHOST");
var fastCgiCollection = fastCgiSection.Collection;
var applicationElement = fastCgiCollection.CreateNewElement("application");
applicationElement.Properties.Item("fullPath").Value = "c:\\php\\php-cgi.exe";
fastCgiCollection.AddElement(applicationElement);
adminManager.CommitChanges();
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Contoso";
var handlersSection = adminManager.GetAdminSection("system.webServer/handlers", "MACHINE/WEBROOT/APPHOST/Contoso");
var handlersCollection = handlersSection.Collection;
var addElement = handlersCollection.CreateNewElement("add");
addElement.Properties.Item("name").Value = "PHP-FastCGI";
addElement.Properties.Item("path").Value = "*.php";
addElement.Properties.Item("verb").Value = "GET,HEAD,POST";
addElement.Properties.Item("modules").Value = "FastCgiModule";
addElement.Properties.Item("scriptProcessor").Value = "c:\\php\\php-cgi.exe";
addElement.Properties.Item("resourceType").Value = "Either";
handlersCollection.AddElement(addElement, 0);
adminManager.CommitChanges();
VBScript
Set adminManager = createObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set fastCgiSection = adminManager.GetAdminSection("system.webServer/fastCgi", "MACHINE/WEBROOT/APPHOST")
Set fastCgiCollection = fastCgiSection.Collection
Set applicationElement = fastCgiCollection.CreateNewElement("application")
applicationElement.Properties.Item("fullPath").Value = "c:\php\php-cgi.exe"
fastCgiCollection.AddElement applicationElement
adminManager.CommitChanges()
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Contoso"
Set handlersSection = adminManager.GetAdminSection("system.webServer/handlers", "MACHINE/WEBROOT/APPHOST/Contoso")
Set handlersCollection = handlersSection.Collection
Set addElement = handlersCollection.CreateNewElement("add")
addElement.Properties.Item("name").Value = "PHP-FastCGI"
addElement.Properties.Item("path").Value = "*.php"
addElement.Properties.Item("verb").Value = "GET,HEAD,POST"
addElement.Properties.Item("modules").Value = "FastCgiModule"
addElement.Properties.Item("scriptProcessor").Value = "c:\php\php-cgi.exe"
addElement.Properties.Item("resourceType").Value = "Either"
handlersCollection.AddElement addElement, 0
adminManager.CommitChanges()