Reputation: 5209
I am using $.ajax
POST method in MVC 2.
There are two texboxes for sending email (Subject, Body).
Our tester is putting below string for negative testing.
^&%@#&*(^!*^#*(!@^#)(!@*#_())(*&^%$&*^*&^*&#&*(^!
And we are getting below error
A potentially dangerous Request.Form value was detected from the client >(email_subject="...^%$&^&^&#&(^").
Can you please us know how can we resolve it using encoding or any suitable solution.
Upvotes: 1
Views: 351
Reputation: 14619
If you just want to avoid this error, try decorating the controller action you are posting to with the [ValidateInput(false)]
or [HttpPost, ValidateInput(false)]
attribute.
You can remove the validation on a specific field of your action by using:
[HttpPost, ValidateInput(true, Exclude = "YourFieldName")]
FYI the attributes of your query string are validated when you submit and special characters create this error. Be careful when using this trick: if your application is for public use, you may use an other solution.
Upvotes: 2