asp.net-mvc 从客户端检测到潜在危险的 Request.Form 值 - ASP.NET MVC
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1455528/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
A potentially dangerous Request.Form value was detected from the client - ASP.NET MVC
提问by Ryall
I am getting this error in my ASP.NET MVC application where I am taking HTML input from a WYSIWYG so I don't want the content validated.
我在我的 ASP.NET MVC 应用程序中收到此错误,我正在从 WYSIWYG 获取 HTML 输入,因此我不希望验证内容。
I have attempted the solution I found herebut it seems to make no difference in my MVC application. I have also tried doing it in the web.config but again - no joy.
Is this a bug in ASP.NET MVC or something?
我已经尝试了我在这里找到的解决方案,但它似乎对我的 MVC 应用程序没有任何影响。我也试过在 web.config 中这样做,但又一次 - 没有乐趣。
这是 ASP.NET MVC 中的错误还是什么?
回答by Craig Stuntz
In MVC you would use the ValidateInput(false) attribute.
在 MVC 中,您将使用ValidateInput(false) 属性。
You then need to sanitize your inputs, e.g. with something like this(built in to ASP.NET 4.5+; use NuGet package for earlier).
那么你需要的东西,如消毒你的投入,如本(内置于ASP.NET 4.5 +;使用NuGet包更早)。
回答by Loren Paulsen
In MVC 3 and later, you can also use the [AllowHtml]attribute. This attribute allows you to be more granular by skipping validation for only one property on your model.
在 MVC 3 及更高版本中,您还可以使用该[AllowHtml]属性。此属性允许您通过跳过模型上仅一个属性的验证来更加细化。
https://docs.microsoft.com/en-us/dotnet/api/system.web.mvc.allowhtmlattribute?view=aspnet-mvc-5.2
https://docs.microsoft.com/en-us/dotnet/api/system.web.mvc.allowhtmlattribute?view=aspnet-mvc-5.2
回答by Pedro Jacinto
Just place this attribute: [ValidateInput(false)] on the action method on the controller that handles the form post.
只需将此属性:[ValidateInput(false)] 放在处理表单发布的控制器上的操作方法上。
回答by JGilmartin
use <httpRuntime requestValidationMode="2.0" />in web config
使用<httpRuntime requestValidationMode="2.0" />的web配置
回答by yogihosting
In your controller action method, (the one which is bringing this) add [ValidateInput(false)]
在您的控制器操作方法中,(带来此功能的方法)添加 [ValidateInput(false)]
Example
例子
[HttpPost]
[ValidateInput(false)]
public ActionResult Insert(FormCollection formCollection, Models.Page page)
{
//your code
return View();
}

