public void OnException(ExceptionContext filterContext) { Config config = new Config(); ResourceStrings resources = new ResourceStrings(config); if (filterContext == null) { throw new ArgumentNullException("filterContext"); } if (filterContext.IsChildAction) { return; } if (filterContext != null && filterContext.Exception != null) { ErrorSignal.FromCurrentContext().Raise(filterContext.Exception); } if (filterContext.ExceptionHandled || !filterContext.HttpContext.IsCustomErrorEnabled) { return; } CustomErrorViewModelBase errorViewModel; HttpException httpException = filterContext.Exception as HttpException; if (httpException != null) { this.Status = httpException.GetHttpCode(); } if (this.Status == 404) { errorViewModel = new Error404ViewModel(resources); } else if (config.IsLocalInstall && CheckForSqlException(filterContext.Exception, resources)) { errorViewModel = new SqlErrorViewModel(resources); } else { errorViewModel = new Error500ViewModel(resources); } filterContext.Result = new ViewResult { ViewName = View, ViewData = new ViewDataDictionary <CustomErrorViewModelBase>(errorViewModel) }; filterContext.ExceptionHandled = true; filterContext.HttpContext.Response.Clear(); filterContext.HttpContext.Response.StatusCode = this.Status; filterContext.HttpContext.Response.TrySkipIisCustomErrors = true; }
public void OnException(ExceptionContext filterContext) { Config config = new Config(); ResourceStrings resources = new ResourceStrings(config); if (filterContext == null) { throw new ArgumentNullException("filterContext"); } if (filterContext.IsChildAction) { return; } if (filterContext != null && filterContext.Exception != null) ErrorSignal.FromCurrentContext().Raise(filterContext.Exception); if (filterContext.ExceptionHandled || !filterContext.HttpContext.IsCustomErrorEnabled) { return; } CustomErrorViewModelBase errorViewModel; HttpException httpException = filterContext.Exception as HttpException; if (httpException != null) { this.Status = httpException.GetHttpCode(); } if (this.Status == 404) { errorViewModel = new Error404ViewModel(resources); } else if (config.IsLocalInstall && CheckForSqlException(filterContext.Exception, resources)) { errorViewModel = new SqlErrorViewModel(resources); } else { errorViewModel = new Error500ViewModel(resources); } filterContext.Result = new ViewResult { ViewName = View, ViewData = new ViewDataDictionary<CustomErrorViewModelBase>(errorViewModel) }; filterContext.ExceptionHandled = true; filterContext.HttpContext.Response.Clear(); filterContext.HttpContext.Response.StatusCode = this.Status; filterContext.HttpContext.Response.TrySkipIisCustomErrors = true; }