public ActionResult UnhandledError() { Exception error = TempData[ErrorViewBuilder.TempData_Key_Exception] as Exception; ErrorViewModel viewmodel = ErrorViewModel.CreateFromError(error, "Unhandled Error Occured"); return(View(viewmodel)); }
private static ViewResult NotAuthorizedViewResult(ControllerContext filterContext) { LogManager.GetLogger(filterContext.Controller.GetType()).Warn("'{0}' is not authorized!", filterContext.HttpContext.User.Identity.Name); Exception error = filterContext.Controller.TempData[ErrorViewBuilder.TempData_Key_Exception] as Exception; String defaultTitle = String.Format("{0} is not authorized for {1}", filterContext.HttpContext.User.Identity.Name, filterContext.HttpContext.Request.Url); ErrorViewModel viewmodel = ErrorViewModel.CreateFromError(error, defaultTitle); ViewDataDictionary viewData = new ViewDataDictionary { Model = viewmodel }; ViewResult viewresult = new ViewResult(); viewresult.ViewName = "NotAuthorized"; viewresult.ViewData = viewData; return(viewresult); }
public static void UnhandledError(ExceptionContext filterContext) { var exception = filterContext.Exception; if (filterContext.HttpContext.Request.IsAjaxRequest()) { var errorObject = new { ErrorMessage = exception.Message, Stacktrace = exception.ToString() }; filterContext.HttpContext.Response.StatusCode = 500; filterContext.Result = new JsonResult() { JsonRequestBehavior = JsonRequestBehavior.AllowGet, ContentType = "application/json", Data = errorObject }; return; } ErrorViewModel viewmodel = ErrorViewModel.CreateFromError(exception, "Unhandled Error Occured"); ViewDataDictionary viewData = new ViewDataDictionary { Model = viewmodel }; ViewResult viewresult = new ViewResult(); viewresult.ViewName = "UnhandledError"; viewresult.ViewData = viewData; filterContext.Result = viewresult; }