标签:style blog http io ar color os sp on
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 }
标签:style blog http io ar color os sp on
原文地址:http://www.cnblogs.com/wzk153/p/4152090.html