Guest User

Untitled

a guest
Jan 20th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. public class RedirectOnErrorAttribute : FilterAttribute, IExceptionFilter {
  2.  
  3. #region IExceptionFilter Members
  4.  
  5. public void OnException(ExceptionContext filterContext) {
  6. if(filterContext.ExceptionHandled) return;
  7.  
  8. filterContext.Controller.TempData["Exception"] = filterContext.Exception;
  9. filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new {area = "Desktop", controller = "Exception", action = "HandleError" }));
  10. filterContext.ExceptionHandled = true;
  11. filterContext.HttpContext.Response.Clear();
  12. filterContext.HttpContext.Response.StatusCode = 500;
  13. filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
  14. }
  15.  
  16. #endregion
  17. }
  18.  
  19. public ActionResult HandleError() {
  20. Exception ex = (Exception)TempData["Exception"];
  21. logger.Log(ex);
  22. }
Add Comment
Please, Sign In to add comment