首页 新闻 会员 周边 捐助

关于ExceptionFilter

0
悬赏园豆:10 [已关闭问题] 关闭于 2011-05-23 15:43

我自定义了一个ExceptionFilter  用于DoRelease这个Action,但结果是异常老是未捕获跳不到错误页面,请问是什么问题呢?本人是刚刚接触ASP.NET MVC模式

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;

namespace MVCDemo.Controllers.Filters
{
    public class ExceptionFilter : FilterAttribute,IExceptionFilter
    {
        void IExceptionFilter.OnException(ExceptionContext filterContext)
        {
            filterContext.Controller.ViewData["ErrorMessage"] = filterContext.Exception.Message;
            filterContext.Result = new ViewResult()
            {
                ViewName = "Error",
                ViewData = filterContext.Controller.ViewData,
            };
            filterContext.ExceptionHandled = true;
        }
    }
}

      [ExceptionFilter()]
        public ActionResult DoRelease()
        {
            AnnounceInfo announce = new AnnounceInfo()
            {
                ID = 1,
                Title = Request.Form["Title"],
                Category = Int32.Parse(Request.Form["Category"]),
                Content = Request.Form["Content"],
            };

            IAnnounceService aServ = ServiceBuilder.BuildAnnounceService();

                aServ.Release(announce);      //该条语句发生异常
   

            ViewData["Announce"] = announce;

            System.Threading.Thread.Sleep(2000);
            ViewData["Time"] = DateTime.Now;
            System.Threading.Thread.Sleep(2000);

            return View("ReleaseSucceed");
        }

百联的主页 百联 | 初学一级 | 园豆:44
提问于:2011-03-21 15:40
< >
分享
所有回答(1)
0

给要拦截异常信息的Controller加[ExceptionFilte]特性声明

Francis.Lou | 园豆:202 (菜鸟二级) | 2013-12-25 00:00
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册