首页 > 代码库 > AOP返回控制器一个实体调用

AOP返回控制器一个实体调用

 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Web.Mvc; 6 using Common; 7 using QianLiFaAuto.User.DAL; 8 using QianLiFaAuto.User.IDAL; 9 using QianLiFaAuto.User.Model;10 11 namespace AOP12 {13 14     15     [AttributeUsage(AttributeTargets.Method)]16     public class AdminUser : FilterAttribute, IActionFilter, IAuthorizationFilter17     {18         /// <summary>19         /// 会员验证方法20         /// </summary>21         /// <param name="filterContext"></param>22         public void OnActionExecuting(ActionExecutingContext filterContext)23         {24             int UserID;25             int.TryParse(CommonCookie.GetCookie("AdminUserID"), out UserID);26             if (CommonCookie.GetCookie("AdminUserID") == null)27             {28                 filterContext.HttpContext.Response.Redirect("/user/adminlogin");29             }30             Admin model = new Admin();31             model.AdminID = UserID;32             model.Name = CommonCookie.GetCookie("AdminUserName");33             filterContext.Controller.ViewBag.Name = model.Name;34 35             if (filterContext.ActionParameters.ContainsKey("user"))36             {37                 filterContext.ActionParameters["user"] = model;38                 39             }40         }41 42         /// <summary>43         /// 44         /// </summary>45         /// <param name="filterContext"></param>46         public void OnAuthorization(AuthorizationContext filterContext)47         {48         }49 50         /// <summary>51         /// 52         /// </summary>53         /// <param name="filterContext"></param>54         public void OnActionExecuted(ActionExecutedContext filterContext)55         {56         }57     }58 }
View Code

 

AOP返回控制器一个实体调用