Guest User

Untitled

a guest
Aug 20th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. how could i catch the MVC3 exception and not return an blank view?
  2. protected override void OnException(ExceptionContext filterContext)
  3. {
  4. base.OnException(filterContext);
  5.  
  6. var exception = new HttpException(null, filterContext.Exception);
  7. if (exception.GetHttpCode() == (int)HttpStatusCode.InternalServerError)
  8. {
  9. if (WebConstants.systemHandleExceptionList.Contains(filterContext.Exception.GetType()))
  10. {
  11. //process the error
  12. SaveErrorMessage(filterContext.Exception.GetType().Name);
  13.  
  14. filterContext.ExceptionHandled = true;
  15. }
  16. else
  17. {
  18. //record the unhandle message to log
  19. errorlog.Error("", filterContext.Exception);
  20. }
  21. }
  22. }
  23.  
  24. RouteValueDictionary errorRouteValues = new RouteValueDictionary( new { controller = "Error", action = "Action" } );
  25.  
  26. filterContext.Result = new ActionRedirectResult( errorRouteValues );
  27. filterContext.Cancel = true;
Add Comment
Please, Sign In to add comment