Пример #1
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var actionName    = filterContext.RouteData.Values["action"];
            var contollerName = filterContext.RouteData.Values["controller"];


            var currentUserRoleIds = _iuserOperation.GetUserRoleIds(filterContext.RequestContext.HttpContext.User.Identity.Name);
            var permissions        = _iuserOperation.GetPermissionsByRole(currentUserRoleIds);

            if (permissions.Contains(PermissioName.ToString()))
            {
                return;
            }

            if (actionName.ToString().ToLower().Contains("index"))
            {
                filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary
                {
                    { "controller", "Error" },
                    { "action", "Index" },
                });
            }
            else
            {
                filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary
                {
                    { "controller", "Error" },
                    { "action", "PartialViewError" },
                });
            }
        }