首页 > Web开发 > 详细

AOP(以MVC中的过滤器为例)

时间:2016-04-04 13:11:35      阅读:346      评论:0      收藏:0      [点我收藏+]
MVC里面的Filter
   public class AOPFilterAttribute : ActionFilterAttribute, IExceptionFilter
    {

        public void OnException(ExceptionContext filterContext)
        {
            throw new System.NotImplementedException();
        }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            
            base.OnActionExecuting(filterContext);
        }

        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            base.OnActionExecuted(filterContext);
        }
    }

在controller里面使用该特性:

     [AOPFilter]
        public JsonResult GetEditModel(string strType)
        {
            var lstRes = new List<List<DragElementProp>>();
            var lstResPage = new List<PageProperty>();

        //.........todo

            return Json(new { lstDataAttr = lstRes, PageAttr = lstResPage, lstJsConnections = lstJsPlumbLines }, JsonRequestBehavior.AllowGet);
        }
调试可知,在执行GetEditModel(string strType)方法之前,会先执行OnActionExecuting()方法,GetEditModel(string strType)之后,又会执行OnActionExecuted()方法。这在我们MVC里面权限验证、错误页导向、日志记录等常用功能都可以方便解决

 

AOP(以MVC中的过滤器为例)

原文:http://www.cnblogs.com/yk123/p/5351766.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!