Why is ValidateInput(False) not working?

With asp.net 4, you’ll need to configure the validation mode in the web.config as well.

Set the following as a child of the <system.web> element:

<system.Web>
  ...
  <httpRuntime requestValidationMode="2.0"/>     

Asp.Net 4 sets the requestValidationMode to 4.0 by default, which tells the system to perform request validation before the BeginRequst phase of the HTTP request. The validation will occur before the system reaches the action attribute telling it not to validate the request, thus rendering the attribute useless. Setting requestValidationMode=”2.0″ will revert to the asp.net 2.0 request validation behavior, allowing the ValidateInput attribute to work as expected.

Leave a Comment