How to get data of ViewModel properties in the OnException method, which is published from the page. In my case, if any error occurs on page i, it is redirected to the error page using OnException, but when I click the back button to go to the page, all the field data is cleared, if I get the viewmodel properties in the onexception method, I I can redirect to a page with these properties.
protected override void OnException(ExceptionContext filterContext)
{
Exception exception = filterContext.Exception;
AppLogging.WriteError(exception);
string controllerName = (string)filterContext.RouteData.Values["controller"];
string actionName = (string)filterContext.RouteData.Values["action"];
var viewData = new ViewDataDictionary<HandleErrorInfo>(filterContext.Controller.ViewData);
viewData.Model = new HandleErrorInfo(filterContext.Exception, controllerName, actionName);
TempData["ErrModel"] = viewData.Model;
filterContext.ExceptionHandled = true;
filterContext.HttpContext.Response.Clear();
filterContext.HttpContext.Response.StatusCode = 500;
filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { { "area", "" }, { "action", "Error" }, { "controller", "Error" } });
Response.TrySkipIisCustomErrors = true;
}
source
share