The AOP (MVC to an example of the filter)

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);
        }
    }

In which the controller characteristic: 

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

        // ..... TODO .... 

            return Json ( new new {lstDataAttr = lstRes, PageAttr = lstResPage, lstJsConnections = lstJsPlumbLines}, JsonRequestBehavior.AllowGet); 
        } 
debugging understood, in performing GetEditModel ( String before strType) method first performs the OnActionExecuting () method, GetEditModel ( StringAfter strType), will perform the OnActionExecuted () method. This is inside us permission MVC validation, error page guide, logging and other commonly used functions can be easily resolved

 

Reproduced in: https: //www.cnblogs.com/yk123/p/5351766.html

Guess you like

Origin blog.csdn.net/weixin_34055787/article/details/94611646