概觀
專案的 <add> 元素 <alwaysAllowedUrls> 會指定要求篩選一律允許的唯一 URL。 元素 <alwaysAllowedUrls> 包含要求篩選允許的集合 URL,這會覆寫集合中的 <denyUrlSequences> 值。
相容性
| 版本 | 備註 |
|---|---|
| IIS 10.0 | 未在 IIS 10.0 中修改專案 <add> 。 |
| IIS 8.5 | 未在 IIS 8.5 中修改專案 <add> 。 |
| IIS 8.0 | 未在 IIS 8.0 中修改專案 <add> 。 |
| IIS 7.5 | 元素 <add> 的 <alwaysAllowedUrls> 元素隨附為 IIS 7.5 的功能。 |
| IIS 7.0 | 元素 <add> 的 <alwaysAllowedUrls> 元素已引進為 IIS 7.0 的更新,可透過 Microsoft 知識庫文章957508 (https://support.microsoft.com/kb/957508) 取得。 |
| IIS 6.0 | 元素 <alwaysAllowedUrls> 大致上類似于新增至 URLScan 3.0 的 [AlwaysAllowedUrls] 區段。 |
安裝程式
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 服務] 和 [ 安全性]。
- 選取 [ 要求篩選],然後按一下 [ 確定]。
作法
如何一律允許 URL
開啟 [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。
在 [連線] 窗格中,移至您要修改要求篩選設定的連線、月臺、應用程式或目錄。
在 [ 首頁] 窗格中,按兩下 [ 要求篩選]。
在 [要求篩選] 窗格中,按一下 [URL] 索引標籤,然後按一下 [動作] 窗格中的 [允許 URL...]。
在 [ 允許 URL ] 對話方塊中,輸入您想要允許的 URL,然後按一下 [ 確定]。
組態
元素 <add> 的 <alwaysAllowedUrls> 元素是在月臺、應用程式或目錄層級設定。
屬性
| 屬性 | 描述 |
|---|---|
url |
選擇性字串屬性。 指定要一律允許的唯一 URL。 沒有任何預設值。 |
子元素
無。
組態範例
下列範例說明一個 <denyUrlSequences> 元素和一個 <alwaysAllowedUrls> 元素的組合,如果它們包含兩個特定字元序列的其中一個,則會拒絕任何 URL,但一律允許特定 URL,其中包含這兩個特定字元序列中的兩個特定順序。
<system.webServer>
<security>
<requestFiltering>
<denyUrlSequences>
<add sequence="bad" />
<add sequence="sequence" />
</denyUrlSequences>
<alwaysAllowedUrls>
<add url="/bad_sequence.txt" />
</alwaysAllowedUrls>
</requestFiltering>
</security>
</system.webServer>
範例程式碼
下列範例示範如何新增一律在預設網站上允許的 URL。
AppCmd.exe
appcmd.exe set config "Default Web Site" -section:system.webServer/security/requestFiltering /+"alwaysAllowedUrls.[url='/_allowed_url.aspx']"
PowerShell
$alwaysAllowedUrls = Get-IISConfigSection -CommitPath 'Default Web Site' -SectionPath 'system.webServer/security/requestFiltering' | Get-IISConfigCollection -CollectionName 'alwaysAllowedUrls'
New-IISConfigCollectionElement -ConfigCollection $alwaysAllowedUrls -ConfigAttribute @{ 'url' = '/_allowed_url.aspx' }
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 alwaysAllowedUrlsCollection = requestFilteringSection.GetCollection("alwaysAllowedUrls");
ConfigurationElement addElement = alwaysAllowedUrlsCollection.CreateElement("add");
addElement["url"] = @"/allowed_url.aspx";
alwaysAllowedUrlsCollection.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 alwaysAllowedUrlsCollection As ConfigurationElementCollection = requestFilteringSection.GetCollection("alwaysAllowedUrls")
Dim addElement As ConfigurationElement = alwaysAllowedUrlsCollection.CreateElement("add")
addElement("url") = "/allowed_url.aspx"
alwaysAllowedUrlsCollection.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 alwaysAllowedUrlsCollection = requestFilteringSection.ChildElements.Item("alwaysAllowedUrls").Collection;
var addElement = alwaysAllowedUrlsCollection.CreateNewElement("add");
addElement.Properties.Item("url").Value = "/allowed_url.aspx";
alwaysAllowedUrlsCollection.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 alwaysAllowedUrlsCollection = requestFilteringSection.ChildElements.Item("alwaysAllowedUrls").Collection
Set addElement = alwaysAllowedUrlsCollection.CreateNewElement("add")
addElement.Properties.Item("url").Value = "/allowed_url.aspx"
alwaysAllowedUrlsCollection.AddElement(addElement)
adminManager.CommitChanges()