public override void OnActionExecuting(ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); var url = new UrlHelper(filterContext.RequestContext); var sysUser = filterContext.HttpContext.User as SysUser; ControllerName = ControllerName ?? filterContext.RouteData.Values["controller"].ToString(); ActionName = ActionName ?? filterContext.RouteData.Values["action"].ToString(); var targetUrl = $"/Admin/{ControllerName}/{ActionName}"; sysUser.UserInfo.FindCurrentMenu(targetUrl); if (sysUser.UserInfo.CurrentMenu == null || !sysUser.HasButton(Buttons)) { if (filterContext.HttpContext.Request.RequestType .Equals("Get", StringComparison.OrdinalIgnoreCase)) { //跳转到无权限页面 var noPerUrl = url.AdminNoPermission(); filterContext.Result = new RedirectResult(noPerUrl); } else { var model = new JsonModel(); model.statusCode = 300; model.message = "对不起,您没有权限进行此项操作!"; var result = new JsonResult(); result.Data = model; filterContext.Result = result; } return; } }
public override void OnActionExecuting(ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); var url = new UrlHelper(filterContext.RequestContext); var adminUser = filterContext.HttpContext.User as AdminUser; var targetUrl = $"/Admin/{filterContext.RouteData.Values["controller"]}/{filterContext.RouteData.Values["action"]}"; adminUser.UserModel.FindCurrentMenu(targetUrl); if (adminUser.UserModel.FirstMenu == null) { //跳转到无权限页面 var noPerUrl = url.AdminNoPermission(); filterContext.Result = new RedirectResult(noPerUrl); return; } }
public override void OnActionExecuting(ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); var url = new UrlHelper(filterContext.RequestContext); var adminUser = filterContext.HttpContext.User as AdminUser; ControllerName = ControllerName ?? filterContext.RouteData.Values["controller"].ToString(); ActionName = ActionName ?? filterContext.RouteData.Values["action"].ToString(); var targetUrl = $"/Admin/{ControllerName}/{ActionName}"; adminUser.UserModel.FindCurrentMenu(targetUrl); if (adminUser.UserModel.FirstMenu == null || !adminUser.HasButton(Buttons)) { //跳转到无权限页面 var noPerUrl = url.AdminNoPermission(); filterContext.Result = new RedirectResult(noPerUrl); } }