When I put HTML characters in my form, for example <br />, ASP.NET throws an internal 500 exception, as described here .
A potentially dangerous Request.Form value was detected from the client (Name="<br />").
Well, that’s why it protects me from unencrypted characters that could be used for malicious reasons.
The problem is that this is nowhere in my long search, this is what needs to be done. That is, my application should not just throw a general internal server error when a user enters bad characters (what if they draw an arrow such as <-).
It’s best to just go back to the error page ModelStatethat says: “Please don't use HTML characters” or something meaningful.
But how to achieve this? Error before it gets into my code. In addition, I don’t want to just disable it through validateRequest="false", and then check each form in my application for HTML characters and return an error.
Is there a way to leave this type of validation enabled, but just handle it differently?
Code for explanation:
Model
Public Class SomeModel
Public Property SomeField As String
End Class
Controller
<HttpPost>
Function SomeController(ByVal model As SomeModel)
' model.SomeField contains some HTML characters :O
' but it doesn't matter, since an internal error has occured :(
End Function
source
share