共用方式為


HttpRuntimeSection.EnableHeaderChecking 屬性

定義

取得或設定一個值,指示標頭檢查是否啟用。

public:
 property bool EnableHeaderChecking { bool get(); void set(bool value); };
[System.Configuration.ConfigurationProperty("enableHeaderChecking", DefaultValue=true)]
public bool EnableHeaderChecking { get; set; }
[<System.Configuration.ConfigurationProperty("enableHeaderChecking", DefaultValue=true)>]
member this.EnableHeaderChecking : bool with get, set
Public Property EnableHeaderChecking As Boolean

屬性值

true若標頭檢查已啟用;否則,。 false 預設值為 true

屬性

範例

以下範例說明如何使用該 EnableHeaderChecking 屬性。

// Get the EnableHeaderChecking property value.
Response.Write("EnableHeaderChecking: " +
  configSection.EnableHeaderChecking + "<br>");

// Set the EnableHeaderChecking property value to true.
configSection.EnableHeaderChecking = true;
' Get the EnableHeaderChecking property value.
Response.Write("EnableHeaderChecking: " & _
  configSection.EnableHeaderChecking & "<br>")

' Set the EnableHeaderChecking property value to true.
configSection.EnableHeaderChecking = True

備註

此特性的目的是使回應標頭中出現的回車字元與換行字 \r\n元及 ,能夠編碼。

在外撥回應標頭中,0x1F及以下代碼所代表的字元被編碼,字元0x7F(刪除字元)也會被編碼。 唯一的例外是字元0x09(制表字元)未被修改。

此編碼有助於避免插入式攻擊,這些攻擊會利用標頭所包含不受信任資料的應用程式。

備註

此屬性不適用於狀態列本身(狀態碼與狀態描述),但應適用於其他標頭。 雖然 <httpRuntime> 可以設定在任何層級,但此特性僅適用於機器層級與應用程式層級。

當此屬性為 true,即預設值時, \r 回應標頭中的 or \n 字元會編碼為 %0d%0a。 這透過讓注入的材料成為同一標頭行的一部分,從而擊敗了標頭注入攻擊。 這可能會破壞回應,但不應該開啟對客戶端的攻擊途徑。 不過,回傳不信任的資料在任何情況下都不是好主意。

這很重要

HTTP 標頭接續依賴跨越多行的標頭,而且需要其中的新行。 如果您需要使用標頭接續,則必須將 EnableHeaderChecking 屬性設定為 false。 由於查看標頭會影響效能,如果你確定已經做了正確的檢查,關閉此功能可以提升應用程式的效能。 停用此功能之前,請確定您已在此區域中採取正確的預防措施。

適用於

另請參閱