Reputation: 10140
I have CustomHandleErrorAttribute
where i override OnException
method like this:
public override void OnException(ExceptionContext filterContext) {
if (!filterContext.ExceptionHandled) {
if (filterContext.HttpContext.Request.Headers["X-Requested-With"] == "XMLHttpRequest") {
filterContext.Result = new JsonResult {
JsonRequestBehavior = JsonRequestBehavior.AllowGet,
Data = new {
error = true,
message = filterContext.Exception.Message
}
};
}
else {
var controllerName = (string)filterContext.RouteData.Values["controller"];
var actionName = (string)filterContext.RouteData.Values["action"];
var model = new HandleErrorInfo(filterContext.Exception, controllerName, actionName);
filterContext.Result = new ViewResult {
ViewName = View,
MasterName = Master,
ViewData = new ViewDataDictionary<HandleErrorInfo>(model),
TempData = filterContext.Controller.TempData
};
}
}
}
I can get exceptions by AJAX request and while my Action
is processing.
I have a problem, when exception thrown (for example on page /Customers/Customer/1
), i have yellow screen
with Server Error in '/' Application
, but i would like to display my view and pass to ViewData
information about exception handled, and then display in on this page (do not redirect to CustomErrorPage
or anywhere else).
So: 1. If i have exception- just display exception info without form; 2. If i don't have exception- display form;
Is it possible, or thrown exception could not continue processing action and displaying same view?
Thx.
Upvotes: 0
Views: 410
Reputation: 239430
You get the yellow screen of death when you allow an exception to bubble all the way up to the level of IIS without being caught. This becomes a 500 Server Error and you will get the yellow screen or your 500 error page, if you've set one. There's nothing else that can be displayed because there's no way to recover from the error.
The only way to get the same view to load is to catch every exception and respond to it in some way. That might be generating an error message for the user on the view or something else, but it's up to you to catch the exception and respond, IIS will not do this for you.
Upvotes: 1