public override void OnActionExecuting(ActionExecutingContext filterContext) { if (string.IsNullOrEmpty(LoginInfo.AdminID)) { string loginUrl = "/account/index"; filterContext.Result = new RedirectResult(loginUrl); } else { if (string.IsNullOrWhiteSpace(ControllerName)) { ControllerName = filterContext.RouteData.Values["controller"].ToString(); } if (string.IsNullOrWhiteSpace(ActionName)) { ActionName = filterContext.RouteData.Values["action"].ToString(); } //判断权限 string[] columns = { Sys_Power.Columns.Id, Sys_Power.Columns.ModuleOperateID, Sys_Power.Columns.RoleID, Sys_ModuleOperate.Columns.KeyCode, Sys_Module.Columns.EnName }; SqlQuery sq = new Select(columns).From <Sys_Power>().LeftOuterJoin(Sys_ModuleOperate.IdColumn, Sys_Power.ModuleOperateIDColumn) .LeftOuterJoin(Sys_Module.IdColumn, Sys_ModuleOperate.ModuleIDColumn); if (ActionName.ToLower() == "index") { sq.Where(Sys_Module.Columns.EnName).IsEqualTo(ControllerName); } else { sq.Where(Sys_Module.Columns.EnName).IsEqualTo(ControllerName); sq.AndExpression(Sys_ModuleOperate.Columns.KeyCode).IsEqualTo(ActionName); } sq.AndExpression(Sys_Power.Columns.RoleID).IsEqualTo(LoginInfo.RoleID); if (sq.GetRecordCount() == 0) { filterContext.Result = new RedirectResult("/account/nopower"); } } }