概觀
<add>
集合中的 <isapiCgiRestriction>
元素可讓您指定個別的 Common Gateway Interface (CGI) 和 Internet Server Application Programming Interface (ISAPI) 應用程式,這些應用程式可以在 Internet Information Services (IIS) 7 上執行。
相容性
版本 | 備註 |
---|---|
IIS 10.0 | 未在 IIS 10.0 中修改專案 <add> 。 |
IIS 8.5 | 未在 IIS 8.5 中修改專案 <add> 。 |
IIS 8.0 | 未在 IIS 8.0 中修改專案 <add> 。 |
IIS 7.5 | 未在 IIS 7.5 中修改專案 <add> 。 |
IIS 7.0 |
<add> 集合的 <isapiCgiRestriction> 元素是在 IIS 7.0 中引進。 |
IIS 6.0 | 集合 <isapiCgiRestriction> 會取代 IIS 6.0 IIsWebService Metabase 物件的WebSvcExtRestrictionList屬性。 |
安裝程式
<isapiCgiRestriction>
只有在您在 IIS 7 和更新版本伺服器上安裝 CGI 或 ISAPI 擴充模組之後,才能使用集合。 您無法將它與這些功能無關安裝。
Windows Server 2012 或 Windows Server 2012 R2
- 在工作列上,按一下 [伺服器管理員]。
- 在[伺服器管理員] 中,按一下 [管理] 功能表,然後按一下 [新增角色及功能]。
- 在 [ 新增角色及功能精 靈] 中,按 [ 下一步]。 選取安裝類型,然後按 [ 下一步]。 選取目的地伺服器,然後按 [ 下一步]。
- 在 [ 伺服器角色] 頁面上,依 序展開 [Web 服務器] ([IIS) ]、[ Web 服務器]、[ 應用程式刪除],然後選取 [CGI ] 或 [ ISAPI 擴充功能]。 按一下 [下一步] 。
.
- 在 [選取功能] 頁面上,按 [下一步]。
- 在 [確認安裝選項] 頁面上,按一下 [安裝]。
- 在 [結果] 頁面上,按一下 [關閉]。
Windows 8 或 Windows 8.1
- 在 [開始] 畫面上,將指標一路移至左下角,以滑鼠右鍵按一下 [開始] 按鈕,然後按一下[主控台]。
- 在主控台中,按一下 [程式和功能],然後按一下 [開啟或關閉 Windows 功能]。
- 依序展開 [Internet Information Services]、[ 萬維網服務]、[ 應用程式開發功能],然後選取 [CGI ] 或 [ ISAPI 擴充功能]。
- 按一下 [確定]。
- 按一下 [關閉] 。
Windows Server 2008 或 Windows Server 2008 R2
- 在工作列上,按一下 [開始],指向 [系統管理工具],然後按一下[伺服器管理員]。
- 在[伺服器管理員階層] 窗格中,展開 [角色],然後按一下 [Web 服務器] (IIS) 。
- 在 [ Web Server (IIS) ] 窗格中,捲動至 [ 角色服務 ] 區段,然後按一下 [ 新增角色服務]。
- 在 [新增角色服務精靈] 的 [選取角色服務] 頁面上,選取[CGI] 或[ISAPI 擴充功能]。
- 如果出現 [ 新增角色服務 ] 對話方塊,請按一下 [ 新增必要的角色服務]。 (只有在您尚未在 server 上安裝任何必要條件角色服務時,才會顯示此頁面。)
- 在 [選取角色服務] 頁面上,按 [下一步]。
- 在 [確認安裝選項] 頁面上,按一下 [安裝]。
- 在 [結果] 頁面上,按一下 [關閉]。
Windows Vista 或 Windows 7
- 在工作列上,按一下 [開始],然後按一下[主控台]。
- 在主控台中,按一下 [程式和功能],然後按一下[開啟或關閉 Windows 功能]。
- 在 [Windows 功能] 對話方塊中,依序展開 [ Internet Information Services]、[ World Wide Web 服務] 和 [ 應用程式開發功能]。
- 選取 [CGI ] 或 [ISAPI 擴充功能],然後按一下 [ 確定]。
作法
如何新增 ISAPI 或 CGI 限制
開啟 [Internet Information Services (IIS) 管理員:
如果您使用 Windows Server 2012 或 Windows Server 2012 R2:
- 在工作列上,依序按一下 [伺服器管理員]、[工具],然後按一下 [Internet Information Services (IIS) Manager]。
如果您使用 Windows 8 或 Windows 8.1:
- 按住Windows鍵,按字母X,然後按一下[主控台]。
- 按一下 [系統管理工具],然後按兩下 [ Internet Information Services (IIS) Manager]。
如果您使用 Windows Server 2008 或 Windows Server 2008 R2:
- 在工作列上,按一下 [ 開始],指向 [ 系統管理工具],然後按一下 [ Internet Information Services (IIS) 管理員]。
如果您使用 Windows Vista 或 Windows 7:
- 在工作列上,按一下 [開始],然後按一下[主控台]。
- 按兩下 [系統管理工具],然後按兩下 [ Internet Information Services] (IIS) Manager。
在 [ 連線] 窗格中,按一下伺服器名稱。
在 [ 首頁] 窗格中,按兩下 [ISAPI] 和 [CGI 限制]。
在 [ 動作 ] 窗格中,按一下 [ 新增...]
在 [ 新增 ISAPI 或 CGI 限制 ] 對話方塊中,于 [ISAPI 或 CGI 路徑 ] 方塊中輸入要新增之二進位檔的路徑,在 [ 描述 ] 方塊中輸入二進位檔的描述,選取 [ 允許延伸模組路徑] 選項執行 核取方塊,以允許二進位檔在伺服器上執行,然後按一下 [ 確定]。
組態
<isapiCgiRestriction>
集合只能在 ApplicationHost.config 檔案的伺服器層級設定。
屬性
屬性 | 描述 |
---|---|
allowed |
必要的布林值屬性。 指定限制是否允許或拒絕在伺服器上執行的 CGI 或 ISAPI 模組。 如需預設值的完整清單,請參閱下方的預設組態一節。 |
描述 | 選擇性字串屬性。 指定與此 groupID 相關聯之群組的易記描述。 如需預設值的完整清單,請參閱下方的預設組態一節。 |
groupId |
選擇性字串屬性。 指定相依于擴充功能限制之應用程式的 groupID。 如需預設值的完整清單,請參閱下方的預設組態一節。 |
path |
必要的字串屬性。 指定伺服器檔案系統中 CGI 或 ISAPI 模組的路徑。 如需預設值的完整清單,請參閱下方的預設組態一節。 |
子元素
無。
組態範例
下列組態範例是在 <isapiCgiRestriction>
安裝 ASP 和 ASP.NET 2.0 版之後,IIS 7.0 的專案組態。
<isapiCgiRestriction>
<add allowed="true" groupId="ASP"
path="%windir%\system32\inetsrv\asp.dll"
description="Active Server Pages" />
<add allowed="true" groupId="ASP.NET v2.0.50727"
path="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll"
description="ASP.NET v2.0.50727" />
</isapiCgiRestriction>
範例程式碼
下列範例會為位於 C:\Inetpub\www.contoso.com\wwwroot 的網站內容資料夾中的自訂 ISAPI 延伸模組新增 ISAPI/CGI 限制。 這些範例會指定 ISAPI 擴充功能的名稱、路徑和群組,並啟用擴充功能。
AppCmd.exe
appcmd.exe set config -section:system.webServer/security/isapiCgiRestriction /+"[path='C:\Inetpub\www.contoso.com\wwwroot\isapi\custom.dll',allowed='True',groupId='ContosoGroup',description='Contoso Extension']" /commit:apphost
注意
當您使用 AppCmd.exe 來設定這些設定時,請務必將 認可 參數 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 isapiCgiRestrictionSection = config.GetSection("system.webServer/security/isapiCgiRestriction");
ConfigurationElementCollection isapiCgiRestrictionCollection = isapiCgiRestrictionSection.GetCollection();
ConfigurationElement addElement = isapiCgiRestrictionCollection.CreateElement("add");
addElement["path"] = @"C:\Inetpub\www.contoso.com\wwwroot\isapi\custom.dll";
addElement["allowed"] = true;
addElement["groupId"] = @"ContosoGroup";
addElement["description"] = @"Contoso Extension";
isapiCgiRestrictionCollection.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.GetApplicationHostConfiguration
Dim isapiCgiRestrictionSection As ConfigurationSection = config.GetSection("system.webServer/security/isapiCgiRestriction")
Dim isapiCgiRestrictionCollection As ConfigurationElementCollection = isapiCgiRestrictionSection.GetCollection
Dim addElement As ConfigurationElement = isapiCgiRestrictionCollection.CreateElement("add")
addElement("path") = "C:\Inetpub\www.contoso.com\wwwroot\isapi\custom.dll"
addElement("allowed") = True
addElement("groupId") = "ContosoGroup"
addElement("description") = "Contoso Extension"
isapiCgiRestrictionCollection.Add(addElement)
serverManager.CommitChanges()
End Sub
End Module
JavaScript
var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var isapiCgiRestrictionSection = adminManager.GetAdminSection("system.webServer/security/isapiCgiRestriction", "MACHINE/WEBROOT/APPHOST");
var isapiCgiRestrictionCollection = isapiCgiRestrictionSection.Collection;
var addElement = isapiCgiRestrictionCollection.CreateNewElement("add");
addElement.Properties.Item("path").Value = "C:\\Inetpub\\www.contoso.com\\wwwroot\\isapi\\custom.dll";
addElement.Properties.Item("allowed").Value = true;
addElement.Properties.Item("groupId").Value = "ContosoGroup";
addElement.Properties.Item("description").Value = "Contoso Extension";
isapiCgiRestrictionCollection.AddElement(addElement);
adminManager.CommitChanges();
VBScript
Set adminManager = createObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set isapiCgiRestrictionSection = adminManager.GetAdminSection("system.webServer/security/isapiCgiRestriction", "MACHINE/WEBROOT/APPHOST")
Set isapiCgiRestrictionCollection = isapiCgiRestrictionSection.Collection
Set addElement = isapiCgiRestrictionCollection.CreateNewElement("add")
addElement.Properties.Item("path").Value = "C:\Inetpub\www.contoso.com\wwwroot\isapi\custom.dll"
addElement.Properties.Item("allowed").Value = True
addElement.Properties.Item("groupId").Value = "ContosoGroup"
addElement.Properties.Item("description").Value = "Contoso Extension"
isapiCgiRestrictionCollection.AddElement(addElement)
adminManager.CommitChanges()