ValidateRequest="false" doesn't work in Asp.Net 4 ValidateRequest="false" doesn't work in Asp.Net 4 asp.net asp.net

ValidateRequest="false" doesn't work in Asp.Net 4


Found solution on the error page itself. Just needed to add requestValidationMode="2.0" in web.config

<system.web>    <compilation debug="true" targetFramework="4.0" />    <httpRuntime requestValidationMode="2.0" /></system.web>

MSDN information: HttpRuntimeSection.RequestValidationMode Property


There is a way to turn the validation back to 2.0 for one page. Just add the below code to your web.config:

<configuration>    <location path="XX/YY">        <system.web>            <httpRuntime requestValidationMode="2.0" />        </system.web>    </location>    ...    the rest of your configuration    ...</configuration>


I know this is an old question, but if you encounter this problem in MVC 3 then you can decorate your ActionMethod with [ValidateInput(false)] and just switch off request validation for a single ActionMethod, which is handy. And you don't need to make any changes to the web.config file, so you can still use the .NET 4 request validation everywhere else.

e.g.

[ValidateInput(false)]public ActionMethod Edit(int id, string value){    // Do your own checking of value since it could contain XSS stuff!    return View();}