c# - Catch Unhandled exception in mvc4 -
c# - Catch Unhandled exception in mvc4 -
how can grab unhandeld exception in mvc4, [without using elmah]. tried invoking application_error
, works logs error including script not found , path of image not found not needed.
example of error can excluded
the controller path '/image/*.png' not found or not implement icontroller
the controller path '/~/scripts/*.js' not found or not implement icontroller
code
void application_error(object sender, eventargs e) { exception exc = server.getlasterror(); //logging exception (exc) }
create custom error handler , grab want (and log it) , ignore don't want.
customhandleerrorattributepublic class customhandleerrorattribute : handleerrorattribute { public override void onexception(exceptioncontext filtercontext) { if (!(filtercontext.exception invalidoperationexception)) { // log } } }
filterconfig you need globally register error handler.
public class filterconfig { public static void registerglobalfilters(globalfiltercollection filters) { filters.add(new handleerrorattribute()); filters.add(new customhandleerrorattribute()); } }
c# asp.net-mvc asp.net-mvc-4
Comments
Post a Comment