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

注解

此属性的用途是启用回车符和换行符和 \n的编码,\r这些字符位于响应标头中。

在出站响应标头中,由0x1F和以下代码表示的字符进行编码,0x7F (删除字符) 。 唯一的例外是选项卡字符0x09 () 未修改。

此编码有助于避免注入攻击,这些注入攻击会攻击对标头包含的不受信数据进行回显的应用程序。

注意

此属性不适用于状态行本身 (状态代码和状态说明) ,但应应用于其他标头。 尽管 <httpRuntime> 可以在任何级别设置,但此属性仅适用于计算机和应用程序级别。

当此属性为 true(默认值)时, \r 在响应标头中找到的 或 \n 字符将编码为 %0d%0a。 这可以通过使注入的材料成为同一标头行的一部分来挫败标头注入攻击。 这可能会中断响应,但不应打开针对客户端的攻击途径。 不过,在任何情况下,回显不受信任的数据都不是一个好主意。

重要

HTTP 标头延续依赖于跨越多行的标头,并且在其中需要换行。 如果需要使用标头延续,则需要将 EnableHeaderChecking 属性设置为 false。 由于查看标头会对性能造成影响,因此,如果确定已经执行了正确的检查,则关闭此功能可以提高应用程序的性能。 在禁用此功能之前,请确保已在这一方面采用正确的预防措施。

适用于

另请参阅