ValidateRequest=“false” and .NET 4 problem

asp.netasp.net-4.0

.NET 4 broke ValidateRequest=“false” for some reason.

The solution is — just put <httpRuntime requestValidationMode="2.0" /> into your web.config file.

The problem with that solution is that it breaks support for .NET 2.0!

IIS refuses to accept unknown attributes in web.config. Also I don't like the all or nothing nature of this.

Can I set requestValidationMode (or in some other way disable request validation) for a single page that needs it? Without breaking backwards compatibility of web.config with 2.0?

Best Answer

I can confirm that the approach of adding validateRequest="true" to the web.config file works and it is marvellous!

Using this makes the page-level directives work correctly again and it avoids the need to change the behaviour back to the ASP.Net2.0 mode.

Strange that it has any effect, seeing as request validation is normally enabled by default anyway, but no matter.

Related Topic