ASP.net 危险提交错误

发布于 2024-10-21 20:58:38 字数 598 浏览 4 评论 0原文

当我尝试运行论坛页面时:

System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client 

在我的 web.config 中我有:

<pages validateRequest="false" smartNavigation="false">

在实际页面上我也有:

<%@ Page Language="C#" AutoEventWireup="true" ValidateRequest="false" MasterPageFile="~/MasterPages/Main.master" %>

但它一直抛出此错误!

编辑

我用以下方法修复了它:

<httpRuntime requestValidationMode="2.0" />

但是它有什么作用以及为什么它有效?

When I try and run a forum page:

System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client 

In my web.config I have:

<pages validateRequest="false" smartNavigation="false">

And on the actual page I also have:

<%@ Page Language="C#" AutoEventWireup="true" ValidateRequest="false" MasterPageFile="~/MasterPages/Main.master" %>

But it keeps throwing this error!

Edit

I fixed it with:

<httpRuntime requestValidationMode="2.0" />

But what's that do and why does it work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

探春 2024-10-28 20:58:38

发生此错误的原因是提交的表单或查询字符串中的某些内容对于 ASP.NET 中的验证来说看起来很危险。

通过添加,

<httpRuntime requestValidationMode="2.0" />

您可以放松应用于 ASP.NET 2 标准的验证。

我想说,尝试准确地找出它在表单/查询字符串中所反对的内容,比仅仅放松验证要好得多。这种严格的验证是为了保护您和您的用户,不应轻易放松。

最近,当我们升级到 ASP.NET MVC3(从版本 2)时,我在我正在从事的一个项目中遇到了这个问题。在我们的例子中,它实际上突出了一个问题,即我们在无意中对查询字符串进行了 url 编码(即,包括问号和与号在内的整个查询字符串都在不应该进行的情况下进行了 url 编码)。

无论您的原因是什么,如果可能的话,请寻找根本原因,而不是放松验证。

This error occurs because something in the submitted form, or in the querystring, looked dangerous to the validation in ASP.NET.

By adding

<httpRuntime requestValidationMode="2.0" />

you are relaxing the validation that is applied back to the standards of ASP.NET 2.

I would say you are far better off trying to work out exactly what it objects to in your form/querystring than just relaxing the validation. This tightened validation is there to protect you and your users, and shouldn't be relaxed lightly.

I have recently hit this on a project I am working on when we upgraded to ASP.NET MVC3 (from version 2). In our case it actually highlighted an issue whereby we were urlencoding our querystring when we didn't mean to (i.e. the entire quertstring including the question mark and the ampersands was all getting url encoded when it shouldn't be).

Whatever your reason, look for the root cause rather than relax the validation if it is at all possible.

飘过的浮云 2024-10-28 20:58:38

提交的文本中可能有标记。 http://www.asp.net/learn/whitepapers/aspnet4/writing-changes

请求验证功能
ASP.NET 提供了一定程度的
默认的跨站防护
脚本(XSS)攻击。在之前的
ASP.NET 版本,请求
默认情况下启用验证。
但是,它仅适用于 ASP.NET
页面(.aspx 文件及其类
文件)并且仅当这些页面是
正在执行。

在 ASP.NET 4 中,默认情况下,请求
为所有启用验证
请求,因为之前已启用
HTTP 的 BeginRequest 阶段
要求。结果,要求
验证适用于所有请求
ASP.NET 资源,而不仅仅是 .aspx 页面
请求。这包括这样的请求
作为 Web 服务调用和自定义 HTTP
处理程序。请求验证也是
当自定义 HTTP 模块处于活动状态时
读取 HTTP 的内容
请求。

因此,请求验证错误
现在可能会发生以下请求
之前没有触发错误。到
恢复到 ASP.NET 的行为
2.0请求验证功能,在
Web.config 文件:


There was probably markup in the submitted text. http://www.asp.net/learn/whitepapers/aspnet4/breaking-changes

The request validation feature in
ASP.NET provides a certain level of
default protection against cross-site
scripting (XSS) attacks. In previous
versions of ASP.NET, request
validation was enabled by default.
However, it applied only to ASP.NET
pages (.aspx files and their class
files) and only when those pages were
executing.

In ASP.NET 4, by default, request
validation is enabled for all
requests, because it is enabled before
the BeginRequest phase of an HTTP
request. As a result, request
validation applies to requests for all
ASP.NET resources, not just .aspx page
requests. This includes requests such
as Web service calls and custom HTTP
handlers. Request validation is also
active when custom HTTP modules are
reading the contents of an HTTP
request.

As a result, request validation errors
might now occur for requests that
previously did not trigger errors. To
revert to the behavior of the ASP.NET
2.0 request validation feature, add the following setting in the
Web.config file:

<httpRuntime requestValidationMode="2.0" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文