The Handleerrorattribute inherits from the FilterAttributeand implements the Iexceptionfilter interface.
An implementation of the AOP idea, the exception handling in the four filters (permissions, actions, results, exceptions) of MVC.
Usage1. Creating custom Exception Handling
Public classapphandleerrorattribute:handleerrorattribute{ Public Override voidonexception (Exceptioncontext filtercontext) {varJSON =NewJsonresponse (); Json.success=false; varex =filtercontext.exception; //deal Custom Exception ...Json.message ="system exception, please contact the administrator!"; stringmsg =string. Format ("System exception: {0}", ex. Message); Loghelper.error (MSG, ex); //log4jnetfiltercontext.exceptionhandled=true; varresult =NewJsonresult (); Result. Data=JSON; Result. Jsonrequestbehavior=Jsonrequestbehavior.allowget; Filtercontext.result=result; }}
2. Registration
Public class filterconfig{ publicstaticvoid registerglobalfilters ( Globalfiltercollection filters) { filters. ADD (new Apphandleerrorattribute ());} }
Reference: http://www.cnblogs.com/linjiancun/archive/2010/09/16/1827937.html