Always Allowed Query Strings < alwaysAllowedQueryStrings>
概觀
元素 <alwaysAllowedQueryStrings>
會指定要求篩選一律允許的查詢字串集合。 元素 <alwaysAllowedQueryStrings>
包含專案的集合 <add>
,這些元素會指定要求篩選允許的查詢字串模式,以覆寫集合中的 <denyQueryStringSequences>
值。
相容性
版本 | 備註 |
---|---|
IIS 10.0 | 未在 IIS 10.0 中修改專案 <alwaysAllowedQueryStrings> 。 |
IIS 8.5 | 未在 IIS 8.5 中修改專案 <alwaysAllowedQueryStrings> 。 |
IIS 8.0 | 未在 IIS 8.0 中修改專案 <alwaysAllowedQueryStrings> 。 |
IIS 7.5 | 元素 <alwaysAllowedQueryStrings> 的 <requestFiltering> 元素隨附為 IIS 7.5 的功能。 |
IIS 7.0 | 元素 <alwaysAllowedQueryStrings> 的 <requestFiltering> 元素已引進為 IIS 7.0 的更新,可透過 Microsoft 知識庫文章957508 (https://support.microsoft.com/kb/957508 ) 取得。 |
IIS 6.0 | 元素 <alwaysAllowedQueryStrings> 大致上類似于新增至 URLScan 3.0 的 [AlwaysAllowedQueryStrings] 區段。 |
安裝程式
IIS 7 和更新版本的預設安裝包含要求篩選角色服務或功能。 如果卸載要求篩選角色服務或功能,您可以使用下列步驟重新安裝它。
Windows Server 2012 或 Windows Server 2012 R2
- 在工作列上,按一下 [伺服器管理員]。
- 在[伺服器管理員] 中,按一下 [管理] 功能表,然後按一下 [新增角色及功能]。
- 在 [ 新增角色及功能精 靈] 中,按 [ 下一步]。 選取安裝類型,然後按 [ 下一步]。 選取目的地伺服器,然後按 [ 下一步]。
- 在 [ 伺服器角色] 頁面上,依序展開 [ Web 服務器] ([IIS) ]、[ Web 服務器]、[ 安全性],然後選取 [ 要求篩選]。 按一下 [下一步] 。
.
- 在 [選取功能] 頁面上,按 [下一步]。
- 在 [確認安裝選項] 頁面上,按一下 [安裝]。
- 在 [結果] 頁面上,按一下 [關閉]。
Windows 8 或 Windows 8.1
- 在 [開始] 畫面上,將指標一路移至左下角,以滑鼠右鍵按一下 [開始] 按鈕,然後按一下[主控台]。
- 在主控台中,按一下 [程式和功能],然後按一下 [開啟或關閉 Windows 功能]。
- 依 序展開 [Internet Information Services]、[ 萬維網服務]、[ 安全性],然後選取 [ 要求篩選]。
- 按一下 [確定]。
- 按一下 [關閉] 。
Windows Server 2008 或 Windows Server 2008 R2
- 在工作列上,按一下 [開始],指向 [系統管理工具],然後按一下[伺服器管理員]。
- 在[伺服器管理員階層] 窗格中,展開 [角色],然後按一下 [Web 服務器] (IIS) 。
- 在 [ Web Server (IIS) ] 窗格中,捲動至 [ 角色服務 ] 區段,然後按一下 [ 新增角色服務]。
- 在 [新增角色服務精靈] 的 [選取角色服務] 頁面上,選取 [要求篩選],然後按 [下一步]。
- 在 [確認安裝選項] 頁面上,按一下 [安裝]。
- 在 [結果] 頁面上,按一下 [關閉]。
Windows Vista 或 Windows 7
- 在工作列上,按一下 [開始],然後按一下[主控台]。
- 在主控台中,按一下 [程式和功能],然後按一下[開啟或關閉 Windows 功能]。
- 依序展開 [Internet Information Services]、[ World Wide Web 服務] 和 [ 安全性]。
- 選取 [ 要求篩選],然後按一下 [ 確定]。
作法
如何允許查詢字串序列
開啟 [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。
在 [連線] 窗格中,移至您要修改要求篩選設定的連線、月臺、應用程式或目錄。
在 [ 首頁] 窗格中,按兩下 [ 要求篩選]。
在 [要求篩選] 窗格中,按一下 [查詢字串]索引標籤,然後按一下 [動作] 窗格中的 [允許查詢字串...]。
在 [ 允許查詢字串] 對話方塊中,輸入您想要封鎖的查詢字串序列,然後按一下 [ 確定]。
組態
元素 <alwaysAllowedQueryStrings>
的 <requestFiltering>
元素是在月臺、應用程式或目錄層級設定。
屬性
無。
子元素
元素 | 描述 |
---|---|
add |
選擇性項目。 將查詢字串模式新增至要求篩選一律允許的查詢字串集合。 |
clear |
選擇性項目。 清除要求篩選一律允許的查詢字串模式集合。 |
remove |
選擇性項目。 從要求篩選一律允許的查詢字串集合中移除查詢字串模式。 |
組態範例
下列範例說明一個 <denyQueryStringSequences>
元素和一個 <alwaysAllowedQueryStrings>
元素的組合,如果它們包含兩個特定字元序列的其中一個,則會拒絕任何查詢字串,但一律允許特定查詢字串,其中包含這兩個特定字元序列中的兩個特定順序。
<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()