ASP.NET MVC中错误处理方式

/// <summary>
        /// 标记了HandleError,并指明错误处理页为AboutError.aspx
        /// </summary>
        /// <returns></returns>
        [HandleError(View = "AboutError")]
        public ActionResult About()
        {
            return View();
        }

 重写OnException

protected override void OnException(ExceptionContext filterContext)
        {
            // 标记异常已处理
            filterContext.ExceptionHandled = true;
            // 跳转到错误页
            filterContext.Result = new RedirectResult(Url.Action("Error", "Shared"));
        }

  参考来源:http://www.cnblogs.com/shenba/archive/2011/04/16/2018441.html

posted @ 2017-10-18 13:57  君宁天下  阅读(152)  评论(0编辑  收藏  举报
野生程序员真的是太难了,一刻也不敢停止学习