系統 FTP 驗證驗證 <>
概觀
元素 <authentication>
會讓您設定可存取伺服器上網站的使用者帳戶。 使用驗證搭配授權來保護伺服器上內容的存取。 驗證會確認使用者的身分識別,而授權會決定使用者可以或無法存取的資源。
IIS 會定義一種類型的驗證規則拒絕規則。 拒絕規則可讓您定義無法存取伺服器上網站的使用者帳戶或使用者群組。
相容性
版本 | 備註 |
---|---|
IIS 10.0 | 未在 IIS 10.0 中修改專案 <authentication> 。 |
IIS 8.5 | 未在 IIS 8.5 中修改專案 <authentication> 。 |
IIS 8.0 | 元素 <authentication> 是在 IIS 8.0 中引進。 |
IIS 7.5 | N/A |
IIS 7.0 | N/A |
IIS 6.0 | N/A |
安裝程式
若要支援在 FTP 伺服器上透過驗證拒絕存取,您必須安裝 FTP 服務角色服務。
Windows Server 2012
按Windows 標誌鍵,然後按一下[伺服器管理員]。
在伺服器管理員中,按一下 [管理],然後按一下 [新增角色及功能]。
在 [ 新增角色及功能] 精靈中:
- 在 [在您開始前] 頁面上,按 [下一步]。
- 在 [ 安裝類型] 頁面上,選取安裝類型,然後按 [ 下一步]。
- 在 [ 伺服器選取 ] 頁面上,選取適當的伺服器,然後按 [ 下一步]。
- 在 [ 伺服器角色] 頁面上,確定已選取 [Web 服務器 (IIS) ],然後展開它。
- 展開 [FTP 伺服器],然後選取 [ FTP 服務和FTP 擴充性],然後按 [ 下一步]。
- 在 [ 功能] 頁面上,按 [ 下一步]。
- 在 [確認安裝選項] 頁面上,按一下 [安裝]。
- 在 [結果] 頁面上,按一下 [關閉]。
Windows 8
- 開啟 Windows [控制台]。
- 在 Windows 主控台中,開啟[程式和功能]。
- 在 [程式和功能] 中,按一下 [開啟或關閉 Windows 功能] 。
- 在 [Windows 功能 ] 對話方塊中,展開 [ Internet Information Services],然後展開 [ FTP 伺服器]。
- 在 [FTP 伺服器] 底下,選取 [ FTP 服務和FTP 擴充性],然後按一下 [ 確定]。
作法
如何根據登入失敗率拒絕存取 FTP 伺服器
開啟 [Internet Information Services (IIS) 管理員:
如果您使用 Windows Server 2012 或更新版本:
- 在工作列上,依序按一下 [伺服器管理員]、[工具],然後按一下 [Internet Information Services (IIS) Manager]。
如果您使用 Windows 8 或更新版本:
- 按住Windows鍵,按字母X,然後按一下[主控台]。
- 按一下 [系統管理工具],然後按兩下 [ Internet Information Services (IIS) Manager]。
在 [ 連線] 窗格中,選取伺服器。
在 [ 首頁] 窗格中,按兩下 [ FTP 登入嘗試限制] 功能。
在 [ FTP 登入嘗試限制 ] 對話方塊中,按一下 [ 啟用 ] 以啟用限制,然後輸入失敗數目上限,以及這些失敗將提示存取 FTP 服務的時間範圍上限。
按一下 [寫入至記錄檔] 以記錄符合條件,但無法封鎖登入嘗試。
在 [動作] 窗格中按一下 [套用]。
組態
元素 <authentication>
是在伺服器層級設定。
屬性
無。
子元素
元素 | 描述 |
---|---|
denyByFailure |
選擇性項目。 設定 FTP 服務,根據失敗率拒絕存取。 |
組態範例
下列範例會設定 <denyByFailure>
專案。
<system.ftpServer>
<security>
<authentication>
<denyByFailure enabled="true" maxFailure="5" entryExpiration="00:00:45" loggingOnlyMode="false" />
</authentication>
</security>
</system.ftpServer>
範例程式碼
下列程式碼範例會根據登入失敗率設定拒絕對 FTP 伺服器的存取。
AppCmd.exe
appcmd.exe set config -section:system.ftpServer/security/authentication /denyByFailure.enabled:"True" /denyByFailure.maxFailure:"10" /denyByFailure.entryExpiration:"00:00:35" /denyByFailure.loggingOnlyMode:"False" /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 authenticationSection = config.GetSection("system.ftpServer/security/authentication");
ConfigurationElement denyByFailureElement = authenticationSection.GetChildElement("denyByFailure");
denyByFailureElement["enabled"] = true;
denyByFailureElement["maxFailure"] = 10;
denyByFailureElement["entryExpiration"] = TimeSpan.Parse("00:00:35");
denyByFailureElement["loggingOnlyMode"] = false;
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 authenticationSection As ConfigurationSection = config.GetSection ("system.ftpServer/security/authentication")
Dim denyByFailureElement As ConfigurationElement = authenticationSection.GetChildElement("denyByFailure")
denyByFailureElement("enabled") = true
denyByFailureElement("maxFailure") = 10
denyByFailureElement("entryExpiration") = TimeSpan.Parse("00:00:35")
denyByFailureElement("loggingOnlyMode") = false
serverManager.CommitChanges
End Sub
End Module
JavaScript
var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var authenticationSection = adminManager.GetAdminSection("system.ftpServer/security/authentication", "MACHINE/WEBROOT/APPHOST");
var denyByFailureElement = authenticationSection.ChildElements.Item("denyByFailure");
denyByFailureElement.Properties.Item("enabled").Value = true;
denyByFailureElement.Properties.Item("maxFailure").Value = 10;
denyByFailureElement.Properties.Item("entryExpiration").Value = "00:00:35";
denyByFailureElement.Properties.Item("loggingOnlyMode").Value = false;
adminManager.CommitChanges();
VBScript
Set adminManager = CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set authenticationSection = adminManager.GetAdminSection("system.ftpServer/security/authentication", "MACHINE/WEBROOT/APPHOST")
Set denyByFailureElement = authenticationSection.ChildElements.Item("denyByFailure")
denyByFailureElement.Properties.Item("enabled").Value = true
denyByFailureElement.Properties.Item("maxFailure").Value = 10
denyByFailureElement.Properties.Item("entryExpiration").Value = "00:00:35"
denyByFailureElement.Properties.Item("loggingOnlyMode").Value = false
adminManager.CommitChanges()
PowerShell
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.ftpServer/security/authentication/denyByFailure" -name "enabled" -value "True"
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.ftpServer/security/authentication/denyByFailure" -name "maxFailure" -value 10
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.ftpServer/security/authentication/denyByFailure" -name "entryExpiration" -value "00:00:35"
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.ftpServer/security/authentication/denyByFailure" -name "loggingOnlyMode" -value "False"