c# - "potentially dangerous Request.Form value" -
I'm getting the error
A potentially dangerous request. The form value was detected by the client
When I apply my application (error does not occur when I run through a local host).
This happens when submitting a form, because one of the fields is HTML. I've added the model around the [AllowHtml] property to a model that matches the offensive field, but it does not seem to work.
For the obvious reasons, Do not want to use [ValidateInput (false)], and at any rate that does not seem to work.
Is there any other configuration what should I do? I have read that
& lt; HttpRuntime requestValidationMode = "2.0" /> The web config file can fix it, but I do not want to add it again because I still need secure verification for other parts of my app.
Any thoughts?
[AllowHtml] need to be added
& Lt; HttpRuntime requestValidationMode = "2.0" /> (Setting this value does not mean that you can not get secure verification, it's just a verification mode). Other parts of the site will be protected, you are disabling verification for only specific assets on your visual model
[Valid input (wrong)] work But as you said it may be less secure because it disables verification for all properties
I have
[AllowHtml] [AllowHtml] .
I will be with both
and
[valid input (wrong)] without the need to work out of the box in ASP.NET MVC 3
& Lt; HttpRuntime requestValidationMode = "2.0" /> Web.config was running under ASP.NET 4.0 in ASP.NET MVC2.
Here's an example:
See model:
Public class MyViewModel {[AllowHtml} public string text {get; Set; Controller: Public class HomeController: Controller {public performance index} {var model = new MyViewModel {text = "& lt; html / & gt;"}; See Return (Model); } [HTPOST] Public Action Result Index (MyView Model Model) {Return View (Model); }}
View:
@model MyViewModel @using (Html.BeginForm ()) {@ Html.TextAreaFor (x => x. Text) & lt; Input type = "submit" value = "ok" /> }
When the form is submitted, no exception is thrown.
Comments
Post a Comment