Alternative to ValidateRequest="false"

Homer picture Homer · Oct 10, 2012 · Viewed 14.7k times · Source

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.

Answer

magnattic picture magnattic · Oct 10, 2012

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"];