protected override bool AuthorizeCore(HttpContextBase httpContext) { if (httpContext == null) { throw new ArgumentNullException("filterContext"); } IIdentity identity = httpContext.User.Identity; var userRights = identity.GetUserRight(); var routeValues = httpContext.Request.RequestContext.RouteData.Values; string controller = routeValues["controller"].ToString().ToLower(), action = routeValues["action"].ToString().ToLower(), rightCode = httpContext.Request["rightCode"], module = string.Empty; if (string.IsNullOrEmpty(rightCode)) { module = string.Concat("/", controller, "/", action); } else { var right = userRights.FirstOrDefault(a => a.SubMenuList.Exists(b => b.SubCode == rightCode))? .SubMenuList.FirstOrDefault(a => a.SubCode == rightCode); if (right != null) { module = right.Url; } else { throw new ArgumentNullException($"权限编码无效{rightCode}"); } } foreach (var right in userRights) { if (!string.IsNullOrEmpty(right.Url)) { string[] paths = right.Url.Split('/').Where(r => !string.IsNullOrEmpty(r)).ToArray(); if (controller == paths[0] && right.All) { return(true); } } else { foreach (var subRight in right.SubMenuList) { if (module.ToLower() == subRight.Url.ToLower()) { return(IdentityHelpers.SwitchActionType(subRight, ActionType, action)); } } } } return(false); }
protected override bool AuthorizeCore(HttpContextBase httpContext) { if (httpContext == null) { throw new ArgumentNullException("filterContext"); } if (!httpContext.User.Identity.IsAuthenticated) { return(false); } IIdentity identity = httpContext.User.Identity; var userRights = identity.GetUserRight(); var routeValues = httpContext.Request.RequestContext.RouteData.Values; string controller = routeValues["controller"].ToString().ToLower(), action = routeValues["action"].ToString().ToLower(); string requestUrl = string.Concat("/", controller, "/", action); foreach (var right in userRights) { if (!string.IsNullOrEmpty(right.Url)) { string[] paths = right.Url.Split('/').Where(r => !string.IsNullOrEmpty(r)).ToArray(); if (controller == paths[0] && right.All) { return(true); } } else { foreach (var subRight in right.SubMenuList) { string[] subPaths = subRight.Url.Split('/').Where(a => !string.IsNullOrEmpty(a)).ToArray(); if (controller == subPaths[0].ToLower()) { return(IdentityHelpers.SwitchActionType(subRight, ActionType, action)); } } } } return(false); }