Ejemplo n.º 1
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //if (AthenticationService.LoggedUser == null)
            //{
            //    filterContext.HttpContext.Response.Redirect("~/Accounts/Login?redirectUrl=" + filterContext.HttpContext.Request.Url);
            //    filterContext.Result = new EmptyResult();

            //}
            //else
            //{
            RolesRepository rolesRepo      = new RolesRepository();
            string          controllerName = filterContext.RouteData.Values[typeof(Controller).Name].ToString() + typeof(Controller).Name;
            string          actionName     = filterContext.RouteData.Values[typeof(Action).Name].ToString();

            foreach (var role in AthenticationService.LoggedUser.Roles)
            {
                if (rolesRepo.Exist(role.Id, controllerName, actionName))
                {
                    base.OnActionExecuting(filterContext);
                    return;
                }
            }
            filterContext.Result = new RedirectResult("~/");
            //}
        }