ValidateRequest = False, but in action, is it still True and ignores it?

I want to disable RequestValidation in a specific view in RTM version of MVC 2.0 . therefore, I added some necessary directives for viewing the section of the page, as shown below:

<%@ Page ValidateRequest="false" Language="C#" MasterPageFile="Path" Inherits="System.Web.Mvc.ViewPage<Path>" %> 

but RequestValidation is not disabled! I also added the RequestValidation attribute for the corresponding action in the controller, as shown below:

 [System.Web.Mvc.ValidateInput(false)] public System.Web.Mvc.ActionResult Create(Model instance) { //Do here something } 

: '), but RequestValidation is not disabled either!

in a previous attempt, set RequestValidation to false in the Web.config file, as shown below:

 <pages validateRequest="false" /> 

RequestValidation is still not disconnecting!

Why? thanks in advance;)

+7
validation asp.net-mvc
source share
2 answers

If you are using asp.net 4.0, the behavior of the validation request function has been changed from version 2.0. View violation changes here . If so, you can solve the problems by setting the request validation behavior to 2.0 in the web.config file as follows:

 <httpRuntime requestValidationMode="2.0" /> 
+11
source share

just add

[ValidateInput (false)]

in the controller function but don’t forget to encode the value to prevent harmful code

  [ValidateInput(false)] public string Browse(string test) { string message = HttpUtility.HtmlEncode("Value = " + test); return message; } 
0
source share