I am developing an MVC5 internet application and have a question in regards to user input having HTML data.
I understand that if I want to have HTML code in a model, I can include the [AllowHtml]
data annotation and then sanitize the objects field.
My question is this, for any object field that does not have the [AllowHtml]
data annotation, where the user enters some HTML code, is it possible to cater to this error rather than have the Error.cshtml
display the error?
Ideally, I would like to display a validation message in the view before the Error.cshtml
displays and logs the error.
Is this possible? How can I cater to the error before the Error.cshtml
displays and logs the error.
Thanks in advance.
UPDATE
I have a function as follows in the Global.asax
file:
protected void Application_Error(object sender, EventArgs e)
This function catches my errors such as when the user goes to a page that does not exist, however, the http error
in question goes directly to the error.cshtml
file.
How can I edit my code so that the Application_Error
function catches this error?
I am using Elmah
for logging and have customErrors mode="On"