为什么有潜在危险的请求错误甚至ValidateRequest = false

pal*_*now 7 .net-4.0 asp.net-4.0

这是我的Default.aspx

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" ValidateRequest="false" %>
<html>
    <head runat="server">
        <title>xss demonstration</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            We are looking for your feedback. 
            <asp:TextBox ID="txtFeedback" runat="server" TextMode="MultiLine" />
            <br />
            <asp:Button ID="submit" runat="server" Text="Submit" onclick="submit_Click" />
            <br />
            Comment: 
            <br />
            <asp:Literal ID="ltlFeedback" runat="server" />
        </div>
        </form>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

以下是Default.aspx.cs

public partial class _Default : System.Web.UI.Page 
{
    protected void submit_Click(object sender, EventArgs e)
    {
        this.ltlFeedback.Text = this.txtFeedback.Text;
    }
}
Run Code Online (Sandbox Code Playgroud)

当我运行应用程序并在文本框中输入以下内容时.

<script>alert('Hello')</script>
Run Code Online (Sandbox Code Playgroud)

我得到以下错误.

从客户端检测到一个潜在危险的Request.Form值(txtFeedback ="alert('Hello ...").

我的问题是,即使在页面中将ValidateRequest设置为false,我也会收到此错误?

ada*_*ost 13

在.net framework 4.0中,您必须<httpRuntime requestValidationMode="2.0"/>在web.config中设置 标记.

<system.web>
     <compilation debug="false" targetFramework="4.0" />
     <httpRuntime requestValidationMode="2.0"/>
</system.web>
Run Code Online (Sandbox Code Playgroud)

看一下参考文章 - ASP.NET 4 Breaking Changes#1:requestValidationMode导致ValidateRequest = False失败.