共用方式為


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 則回應標頭中找到的 或 \n 字元會編碼為 %0d%0a 。 這可藉由讓插入的材質部分成為同一行的標頭插入式攻擊,而使標頭插入攻擊失效。 這可能會中斷回應,但不應該對用戶端開啟攻擊向量。 不過,在任何情況下,回顯不受信任的資料永遠不會是個不錯的主意。

重要

HTTP 標頭接續依賴跨越多行的標頭,並要求它們中的新行。 如果您需要使用標頭接續,您必須將 EnableHeaderChecking 屬性設定為 false 。 由於查看標頭會對效能造成影響,如果您確定已經執行正確的檢查,關閉此功能可以改善應用程式的效能。 停用此功能之前,請確定您已在此區域中採取正確的預防措施。

適用於

另請參閱