Alternative to ValidateRequest=”false”

asp.nethttp-postvalidate-request

Is there a way to prevent the error "A potentially dangerous Request.Form value was detected from the client" other than setting ValidateRequest="false"?

Update: I removed the "on the page" part. I'd like to not use ValidateRequest="false" at all, on the page or in web.config.

Best Answer

Check out the new ASP.NET 4.5 request validation features.

If you set

<httpRuntime requestValidationMode="4.5" ... />

in your web.config, values will only get validated when you access them. This is called deferred validation.

Also you can get unvalidated values via

var s = context.Request.Unvalidated.Form["forum_post"];