asp.net mvc - replacement for try catch(MyEx ex) in each action -


I want something that works like this:

  Public ActionRisalt AC ( ) {Try {// stuff ...} Catch (pre-expiration) {// handle}}  

but do not try to catch in every action method

You want to annotate your classes with HandleErrorAttribute -

If the functionality built into the above handler is not sufficient, then you can define your class which implements IExceptionFilter - the result of the on-premises method and an exception concert object with the HttpContext properties, Which you can use to control the result:

  Public class MyHandleErrorAttribute: FilterAttribute, IExceptionFilter {public zero on option (exception comment box filter context) {A Debate e = filterContext.Exception; // Some logging etc come here (! FilterContext.ExceptionHandled & amp; amp; amp; amp; amp; ContactContacts.httpContext.IsCustomErrorEnabled) {ViewResult lResult = ... filterContext.Result = lResult; FilterContext.ExceptionHandled = True; FilterContext.HttpContext.Response.Clear (); FilterContext.HttpContext.Response.StatusCode = 500; FilterContext.HttpContext.Response.TrySkipIisCustomErrors = True; }}  

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -