Ответ 1
Это связано с тем, что HandleErrorAttribute изменяет ViewData, переданные в представление при возникновении ошибки. Он передает экземпляр класса HandleErrorInfo с информацией об исключении, контролере и действии.
Что вы можете сделать, это заменить этот атрибут следующим:
using System;
using System.Web;
using System.Web.Mvc;
public class MyHandleErrorAttribute : HandleErrorAttribute {
public override void OnException(ExceptionContext filterContext)
{
if (filterContext == null)
{
throw new ArgumentNullException("filterContext");
}
if (!filterContext.ExceptionHandled && filterContext.HttpContext.IsCustomErrorEnabled)
{
Exception innerException = filterContext.Exception;
if ((new HttpException(null, innerException).GetHttpCode() == 500) && this.ExceptionType.IsInstanceOfType(innerException))
{
string controllerName = (string) filterContext.RouteData.Values["controller"];
string actionName = (string) filterContext.RouteData.Values["action"];
// Preserve old ViewData here
var viewData = new ViewDataDictionary<HandleErrorInfo>(filterContext.Controller.ViewData);
// Set the Exception information model here
viewData.Model = new HandleErrorInfo(filterContext.Exception, controllerName, actionName);
filterContext.Result = new ViewResult { ViewName = this.View, MasterName = this.Master, ViewData = viewData, TempData = filterContext.Controller.TempData };
filterContext.ExceptionHandled = true;
filterContext.HttpContext.Response.Clear();
filterContext.HttpContext.Response.StatusCode = 500;
filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
}
}
}
}