码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-12-08 22:59:52      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   os   sp   on   

bubuko.com,布布扣
 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 AOP
12 {
13 
14     
15     [AttributeUsage(AttributeTargets.Method)]
16     public class AdminUser : FilterAttribute, IActionFilter, IAuthorizationFilter
17     {
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返回控制器一个实体调用

标签:style   blog   http   io   ar   color   os   sp   on   

原文地址:http://www.cnblogs.com/wzk153/p/4152090.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!