危险的请求.从客户端检测到表单值-为什么?



我阅读了这里所有与此错误相关的帖子。也许我在这里遗漏了什么,但我不知道是什么。我正在使用textArea输入文本在它(html文本)。
这个文本区域限定在我的域类属性

public class SomeClass{
...
[AllowHtml]       
        public string CommentText { get; set; }
...
}

我也试图添加[ValidateInput(false)]属性,但没有。但是通过阅读错误文本,我看到请求甚至没有到达控制器,它在Application_BeginRequest()中被打破。这是错误信息:

A potentially dangerous Request.Form value was detected from the client (CommentText="<p>ddd</p>")
Line 23:         protected void Application_BeginRequest(Object sender, EventArgs e)
Line 24:         {
Line 25:             if (HttpContext.Current.Request["RequireUploadifySessionSync"] != null)
Line 26:                 UploadifySessionSync();
Line 27:         }
Source File: D:Projects...Global.asax.cs    Line: 25 
Stack Trace: 

[HttpRequestValidationException (0x80004005): A potentially dangerous Request.Form value was detected from the client (CommentText="<p>ddd</p>").]
   System.Web.HttpRequest.ValidateString(String value, String collectionKey, RequestValidationSource requestCollection) +8755668
   System.Web.HttpRequest.ValidateNameValueCollection(NameValueCollection nvc, RequestValidationSource requestCollection) +122
   System.Web.HttpRequest.get_Form() +114

我知道我可以在web配置中关闭检查整个应用程序。但是我只在一种情况下需要这个(允许HTML输入)。
更奇怪的是,这工作几天前,我没有改变任何东西在这里,只是登录和注销用户。
我哪里做错了?
现在我从global。asax:

中删除这段代码
if (HttpContext.Current.Request["RequireUploadifySessionSync"] != null)
                UploadifySessionSync();

现在它工作了。但我需要这里的代码。为什么会产生这个错误?

这个问题已经有答案了。

前一个问题

您需要更改处理请求验证的方式以将其恢复到2.0

你的具体问题是,你有代码看请求参数在BeginRequest这是早期的ASP。. NET管道比绑定模型(其中AllowHtmlValidateInput属性将发挥作用)。

看起来你是围绕flash上传的代码强制安全(我正在做一些非常类似的事情。

在我的情况下,我最终只是在BeginRequest方法中捕获HttpRequestValidationException并吞下异常。这不是最佳实践,但验证将在稍后的管道中执行,因此您仍然可以控制验证。

最新更新