I am developing an MVC5 web application and asking a question regarding user input of HTML data.
I understand that if I want to have HTML code in the model, I can enable data annotation [AllowHtml]and then sanitize the object field.
My question is that for any field of an object that does not have data annotation [AllowHtml], where the user enters some HTML code, is it possible to satisfy this error and not show the Error.cshtmlerror?
Ideally, I would like to display a validation message in the view before it Error.cshtmldisplays and logs the error.
Is it possible? How can I handle the error before it Error.cshtmldisplays and logs the error.
Thanks in advance.
UPDATE
I have the following function in a file Global.asax:
protected void Application_Error(object sender, EventArgs e)
This function catches my mistakes, for example, when the user goes to a page that does not exist, but http erroris located directly in the file Error.cshtml.
How can I change my code so that the function Application_Errorcatches this error?
I use Elmahfor logging andcustomErrors mode="On"
source
share