从客户端检测到危险的 Request.Form 值 - 为什么?
我在这里阅读了与此错误相关的所有其他帖子。也许我在这里遗漏了一些东西,但我不知道是什么。我正在使用 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();
现在它可以工作了。但我这里需要这段代码。为什么会产生这个错误呢?
I read all other posts here that are related to this error. Maybe I am missing something here but I don't know what. I am using textArea to input text in it (html text).
This text area is bounded to my domain class property
public class SomeClass{
...
[AllowHtml]
public string CommentText { get; set; }
...
}
I have also tried to add [ValidateInput(false)] attribute but nothing. But by reading error text I see that request doesn't even come to controller it is broken in Application_BeginRequest().
This is error message:
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
I know that I can turn off check ok whole application in web config. But I need this only in one case (to allow HTML input).
More strange is that this works a few days ago and I didn't change anything here, just login and logout users.
What am I doing wrong here?
Ok now I remove this code fom global.asax:
if (HttpContext.Current.Request["RequireUploadifySessionSync"] != null)
UploadifySessionSync();
And now it works. But I need this code here. Why is it produce this error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这已经得到了回答。
上一个问题
您需要更改处理请求验证的方式以将其恢复到 2.0
This has already been answered.
Previous Question
You need to change the way your handling request validations to revert it back to 2.0
您的具体问题是,您有查看 BeginRequest 中的请求参数的代码,该代码在 ASP.NET 管道中比绑定模型时更早(其中
AllowHtml
或ValidateInput 属性将发挥作用)。
看起来您正在使用代码强制执行 Flash 上传的安全性(我正在做一些非常类似的事情。
在我的例子中,我最终只是在 BeginRequest 方法中捕获了
HttpRequestValidationException
这不是最佳实践,但验证将在管道中稍后执行,因此您仍然可以控制验证。Your specific issue is that you've got code looking at the request parameters in BeginRequest which is earlier in the ASP.NET pipeline than when your models are bound (where an
AllowHtml
orValidateInput
attribute would come into play).It looks like you are enforcing security around a flash upload with your code (I am doing something very similar.
In my case I ended up just catching an
HttpRequestValidationException
in the BeginRequest method and swallowing the exception. It is not best practice, but the validation will be performed later in the pipeline so you still have control over the validation.