1
public override void OnException(ExceptionContext filterContext) {
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;
,但我得到的錯誤:C#mvc4 ViewResult如何設置控制器和區域?
{System.InvalidOperationException: The view 'Error' or its master was not found or no view engine supports the searched locations. The following locations were searched:
xxxxxxxx
,但我的位置不是搜索。錯誤方法在MyErrorController中。我怎樣才能明確設置控制器(MyErrorController
)
我的路徑必須是〜/地區/公共/瀏覽/ MyError/Error.ascx
"area" -> "Public"
"controller", "MyError"
"action" -> "Error";
什麼是'this.View'? – haim770 2014-10-30 16:08:04
這是多餘的! – senzacionale 2014-10-30 17:20:36
你在寫'ActionFilter'嗎?它沒有定義'View'屬性。 – haim770 2014-10-30 17:26:35