这是MVC的机制,这个方法是重写了执行方法之前的这个方法,不过需要在控制器上或者方法上加上下面这个代码
那么接下来就说下我的判断思路:
(!WebCookieHelper.AdminCheckLogin()) { filterContext.Result = , true); return; }
View Code这是用来先检测下用户是否登录,如果没有登录则直接回到登录页面,
(WebCookieHelper.GetAdminId(5) == 1) { return; }
View Code这是如果进来的用户是超级管理员那么就直接显示要显示的页面页面即可,左边菜单栏晚点讲。
customAttributes = filterContext.ActionDescriptor.GetCustomAttributes(true); if (customAttributes != null && customAttributes.Length > 0) { for (int i = 0; i < customAttributes.Count(); i++) { ) {actionCode = (customAttributes[i] actionUrl = (customAttributes[i] actionResultType = (customAttributes[i] as AdminActionMethod).ActionResultType;//获取返回视图类型
View Code利用这个来抓取用户当前要执行的方法,然后对其作出相应的处理,
List<AuthorDesign.Model.AdminPageAction> pageActionList = AdminMenuHelper.GetNowAdminMenu();
View Code这行代码用来加载当前要显示的全部页面
获取管理员可操作菜单列表 List<Model.AdminPageAction> GetAdminMenu(int adminId) { )) { Dictionary<) as Dictionary<int, List<Model.AdminPageAction>>; List<Model.AdminPageAction> adminMenuList = adminMenuListDic[adminId]; if (adminMenuList == null) { adminMenuList = EnterRepository.GetRepositoryEnter().GetPageMenuRepository.GetAdminShowPage(adminId); adminMenuListDic.Add(adminId, adminMenuList); CacheHelper.AddCache(, adminMenuListDic, 2); } return adminMenuList; } else { List<Model.AdminPageAction> adminMenuList = EnterRepository.GetRepositoryEnter().GetPageMenuRepository.GetAdminShowPage(adminId); Dictionary<int, List<Model.AdminPageAction>> adminMenuListDic = new Dictionary<int, List<Model.AdminPageAction>>(); adminMenuListDic.Add(adminId, adminMenuList); CacheHelper.AddCache(, adminMenuListDic, 2); return adminMenuList; } //if (CacheHelper.IsExistCache("AdminMenuList_"+adminId)) { // return CacheHelper.GetCache("AdminMenuList_" + adminId) as List<Model.AdminPageAction>; //} //else { // List<Model.AdminPageAction> adminMenuList = EnterRepository.GetRepositoryEnter().GetPageMenuRepository.GetAdminShowPage(adminId); // CacheHelper.AddCache("AdminMenuList_" + adminId, adminMenuList, 1); // return adminMenuList; //} //return EnterRepository.GetRepositoryEnter().GetPageMenuRepository.GetAdminShowPage(adminId); } 获取当前管理员可操作菜单列表(超级管理员另取) List<Model.AdminPageAction> GetNowAdminMenu() { return GetAdminMenu(WebCookieHelper.GetAdminId(0)); }
View Code这里我用缓存做了下处理,不知道处理的好不好,还望你们指点我一下。