【问题标题】:ASP.NET Request Validation and Server-side validationASP.NET 请求验证和服务器端验证
【发布时间】:2012-08-13 15:56:35
【问题描述】:

我对 ASP.NET 请求验证和服务器端验证感到困惑。 如果我们设置ValidateRequest="false",如下。

<%@ Language="C#" ValidateRequest="false" %>
<html>
  <script runat="server">
   void btnSubmit_Click(Object sender, EventArgs e)
   {
      // If ValidateRequest is false, then 'hello' is displayed
      // If ValidateRequest is true, then ASP.NET returns an exception
      Response.Write(txtString.Text);
   }
  </script>
<body>
  <form id="form1" runat="server">
    <asp:TextBox id="txtString" runat="server" 
             Text="<script>alert('hello');</script>" />
    <asp:Button id="btnSubmit" runat="server" OnClick="btnSubmit_Click" 
             Text="Submit" />
  </form>
</body>
</html>

那我们可以使用RequiredFieldValidator控件这样的服务端验证吗?

它们是不同的东西吗?但他们都有 validate 关键字。

感谢您的解释。

【问题讨论】:

    标签: asp.net validation


    【解决方案1】:

    是的,它们是不同的。

    ValidateRequest 会在任何提交的表单字段值包含“危险”值(例如您那里的脚本标记)时引发错误并中止请求,以防止脚本注入攻击。

    RequiredFieldValidator 等验证器控件在失败时不会停止页面处理。它们用于帮助您处理规则,通常与保护服务器或应用程序免受攻击无关。

    【讨论】:

      猜你喜欢
      • 2011-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-28
      • 2023-03-12
      相关资源
      最近更新 更多