概觀
元素 <add> 的 <alwaysAllowedQueryStrings> 元素會指定要求篩選允許的唯一查詢字串模式。 專案中的值 <alwaysAllowedQueryStrings> 會覆寫集合中的 <denyQueryStringSequences> 值。
相容性
| 版本 | 備註 |
|---|---|
| IIS 10.0 | 在 <add> IIS 10.0 中未修改專案。 |
| IIS 8.5 | 未 <add> 在 IIS 8.5 中修改專案。 |
| IIS 8.0 | 在 IIS 8.0 中未修改專案 <add> 。 |
| IIS 7.5 | 元素 <add> 的 <alwaysAllowedQueryStrings> 元素會隨附為 IIS 7.5 的功能。 |
| IIS 7.0 | 元素 <add> 的 <alwaysAllowedQueryStrings> 元素是透過 Microsoft 知識庫文章957508 () https://support.microsoft.com/kb/957508 引進的 IIS 7.0 更新。 |
| IIS 6.0 | 元素 <alwaysAllowedQueryStrings> 大致類似于新增至 URLScan 3.0 的 [AlwaysAllowedQueryStrings] 區段。 |
安裝程式
IIS 7 和更新版本的預設安裝包含要求篩選角色服務或功能。 如果卸載要求篩選角色服務或功能,您可以使用下列步驟重新安裝它。
Windows Server 2012 或 Windows Server 2012 R2
- 在工作列上,按一下 [伺服器管理員]。
- 在伺服器管理員中,按一下 [管理]功能表,然後按一下 [新增角色和功能]。
- 在 [ 新增角色和功能 精靈] 中,按 [下一步]。 選取安裝類型,然後按 [ 下一步]。 選取目的地伺服器,然後按 [ 下一步]。
- 在 [ 伺服器角色] 頁面上,依序展開 [Web 服務器] ([IIS) ]、[ 網頁伺服器]、[ 安全性],然後選取 [ 要求篩選]。 按一下 [下一步] 。
. - 在 [選取功能] 頁面上,按 [下一步]。
- 在 [確認安裝選項] 頁面上,按一下 [安裝]。
- 在 [結果] 頁面上,按一下 [關閉]。
Windows 8 或Windows 8.1
- 在 [開始] 畫面上,將指標全部移至左下角,以滑鼠右鍵按一下 [開始] 按鈕,然後按一下[主控台]。
- 在主控台中,按一下 [程式和功能],然後按一下 [開啟或關閉 Windows 功能]。
- 展開 [網際網路資訊服務]、[ 萬維網服務]、[ 安全性],然後選取 [ 要求篩選]。
- 按一下 [確定]。
- 按一下 [關閉] 。
Windows Server 2008 或 Windows Server 2008 R2
- 在工作列上,按一下 [開始],指向 [系統管理工具],然後按一下[伺服器管理員]。
- 在[伺服器管理員階層] 窗格中,展開 [角色],然後按一下 [Web 服務器] (IIS) 。
- 在 [Web 服務器 (IIS) ] 窗格中,捲動至 [ 角色服務 ] 區段,然後按一下 [ 新增角色服務]。
- 在 [新增角色服務精靈] 的 [選取角色服務] 頁面上,選取 [要求篩選],然後按 [下一步]。
- 在 [確認安裝選項] 頁面上,按一下 [安裝]。
- 在 [結果] 頁面上,按一下 [關閉]。
Windows Vista 或 Windows 7
- 在工作列上,按一下 [開始],然後按一下[主控台]。
- 在主控台中,按一下 [程式和功能],然後按一下 [開啟或關閉 Windows 功能]。
- 展開 [Internet Information Services],然後展開 [萬維網服務],然後展開 [安全性]。
- 選取 [要求篩選],然後按一下 [ 確定]。
作法
如何允許查詢字串序列
(IIS) 管理員開啟 Internet Information Services:
如果您使用 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) 管理員]。
在 [連線] 窗格中,移至您要修改要求篩選設定的連線、月臺、應用程式或目錄。
在 [ 首頁] 窗格中,按兩下 [ 要求篩選]。
在 [要求篩選]窗格中,按一下 [查詢字串] 索引標籤,然後按一下 [動作] 窗格中的 [允許查詢字串...]。
在 [ 允許查詢字串 ] 對話方塊中,輸入您想要封鎖的查詢字串序列,然後按一下 [ 確定]。
組態
專案的 <add> 元素 <alwaysAllowedQueryStrings> 是在月臺、應用程式或目錄層級設定。
屬性
| 屬性 | 描述 |
|---|---|
queryString |
選擇性字串屬性。 指定要一律允許的查詢字串。 沒有任何預設值。 |
子元素
無。
組態範例
下列範例說明專案和 <alwaysAllowedQueryStrings> 專案的組合,如果其中一個 <denyQueryStringSequences> 包含兩個特定字元序列,則會拒絕任何查詢字串,但一律允許特定查詢字串,其中包含特定順序的這兩個特定字元序列。
<system.webServer>
<security>
<requestFiltering>
<denyQueryStringSequences>
<add sequence="bad" />
<add sequence="sequence" />
</denyQueryStringSequences>
<alwaysAllowedQueryStrings>
<add queryString="bad=sequence" />
</alwaysAllowedQueryStrings>
</requestFiltering>
</security>
</system.webServer>
範例程式碼
下列範例示範如何新增一律在預設網站上允許的查詢字串。
AppCmd.exe
appcmd.exe set config "Default Web Site" -section:system.webServer/security/requestFiltering /+"alwaysAllowedQueryStrings.[queryString='allowed=sequence']"
PowerShell
$alwaysAllowedQueryStrings = Get-IISConfigSection -CommitPath 'Default Web Site' -SectionPath 'system.webServer/security/requestFiltering' | Get-IISConfigCollection -CollectionName 'alwaysAllowedQueryStrings'
New-IISConfigCollectionElement -ConfigCollection $alwaysAllowedQueryStrings -ConfigAttribute @{ 'queryString' = 'allowed=sequence' }
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.GetWebConfiguration("Default Web Site");
ConfigurationSection requestFilteringSection = config.GetSection("system.webServer/security/requestFiltering");
ConfigurationElementCollection alwaysAllowedQueryStringsCollection = requestFilteringSection.GetCollection("alwaysAllowedQueryStrings");
ConfigurationElement addElement = alwaysAllowedQueryStringsCollection.CreateElement("add");
addElement["queryString"] = @"allowed=sequence";
alwaysAllowedQueryStringsCollection.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.GetWebConfiguration("Default Web Site")
Dim requestFilteringSection As ConfigurationSection = config.GetSection("system.webServer/security/requestFiltering")
Dim alwaysAllowedQueryStringsCollection As ConfigurationElementCollection = requestFilteringSection.GetCollection("alwaysAllowedQueryStrings")
Dim addElement As ConfigurationElement = alwaysAllowedQueryStringsCollection.CreateElement("add")
addElement("queryString") = "allowed=sequence"
alwaysAllowedQueryStringsCollection.Add(addElement)
serverManager.CommitChanges()
End Sub
End Module
JavaScript
var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Default Web Site";
var requestFilteringSection = adminManager.GetAdminSection("system.webServer/security/requestFiltering", "MACHINE/WEBROOT/APPHOST/Default Web Site");
var alwaysAllowedQueryStringsCollection = requestFilteringSection.ChildElements.Item("alwaysAllowedQueryStrings").Collection;
var addElement = alwaysAllowedQueryStringsCollection.CreateNewElement("add");
addElement.Properties.Item("queryString").Value = "allowed=sequence";
alwaysAllowedQueryStringsCollection.AddElement(addElement);
adminManager.CommitChanges();
VBScript
Set adminManager = createObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Default Web Site"
Set requestFilteringSection = adminManager.GetAdminSection("system.webServer/security/requestFiltering", "MACHINE/WEBROOT/APPHOST/Default Web Site")
Set alwaysAllowedQueryStringsCollection = requestFilteringSection.ChildElements.Item("alwaysAllowedQueryStrings").Collection
Set addElement = alwaysAllowedQueryStringsCollection.CreateNewElement("add")
addElement.Properties.Item("queryString").Value = "allowed=sequence"
alwaysAllowedQueryStringsCollection.AddElement(addElement)
adminManager.CommitChanges()