views:

21

answers:

1

Is there a way to disable request validation for just certain textboxes instead of the whole page? I'm using Server.HtmlEncode/Decode because users are legitimately using < and > characters but I don't want to use ValidateRequest="false" on the whole page because someone could add a textbox later and forget to escape the input in which case I would want validation to occur so the error would be discovered rather than be vulnerable to html injection.

It seems like there has to be a simple solution but I'm not having any luck finding it.

(Webforms not MVC)

+3  A: 

No, request validation is for the entire request and cannot be done on an element by element basis. Request validation is enabled by ASP.NET by default and is to help those out that do not know about sanitizing HTML inputs from script injection attacks. Posted some links below for further reading:

MSDN

Stackoverflow

Tommy
I find it incredulous that there's no way to do it per-control. Even someone that knows what they're doing can occasionally forget and it'd be good to have a fallback. However +1 anyway because I haven't been able to find anything to the contrary. If nothing comes up by tomorrow I'll accept.
Davy8
Maybe something for .NET 5.0 :)
Tommy
I agree that it's ridiculous that this isn't supported, but my understanding is that @Tommy is correct, it really isn't possible in current ASP.NET.
Stuart
If you want to turn this on for an individual control you will have to do it yourself. Honestly if you use reflector to look at the algorithm it isn't terribly complicated. Essentially it just looks for some very basic offending characters and kicks them out. However, I might mention that it is using an "unsafe" keyword for performance reasons, but it has to look at the entire request, not just a single control.
Josh