Beispiel #1
0
        public override sealed void OnActionExecuting(ActionExecutingContext filterContext)
        {
            string message = WillRedirect(filterContext);

            if (message != null)
            {
                SetMessage(filterContext, message);

                Log.Warning(string.Format("'{0}' Redirecting from '{1}.{2}({3})child {4}, off inherited {5}' to '{6}.{7}' '{8}'",
                                          GetType().Name,
                                          ActionExecutingContextHelper.GetControllerName(filterContext),
                                          ActionExecutingContextHelper.GetActionName(filterContext),
                                          ActionExecutingContextHelper.GetHttpMethod(filterContext),
                                          ActionExecutingContextHelper.IsChildAction(filterContext),
                                          IsOffInherited(filterContext),
                                          RedirectionController,
                                          RedirectionAction,
                                          message));

                filterContext.Result = new RedirectToRouteResult(
                    new RouteValueDictionary
                {
                    { MvcConstants.ControllerRouteValueKey, RedirectionController },
                    { MvcConstants.ActionRouteValueKey, RedirectionAction }
                });

                OnRedirecting(filterContext);
            }

            base.OnActionExecuting(filterContext);
        }
Beispiel #2
0
        protected virtual string NeedRedirection(ActionExecutingContext filterContext)
        {
            var permissionChecker = filterContext.Controller as IPermissionChecker;
            var action            = ActionExecutingContextHelper.GetAction(filterContext);

            if (action == null)
            {
                return("Url non existante");
            }
            if (action.IsAlwaysAuthorized())
            {
                return(null);
            }

            if (permissionChecker == null)
            {
                return(NotImplementingPermissionErrorMessage);
            }

            return(permissionChecker.CheckUserPermissions(filterContext));
        }
Beispiel #3
0
 private string WillRedirect(ActionExecutingContext filterContext)
 {
     if (Disabled)
     {
         return(null);
     }
     if (Off)
     {
         return(null);
     }
     if (IsOffInherited(filterContext))
     {
         return(null);
     }
     if (ActionExecutingContextHelper.IsChildAction(filterContext))
     {
         return(null);
     }
     if (ActionExecutingContextHelper.GetActionName(filterContext) == RedirectionAction && ActionExecutingContextHelper.GetControllerName(filterContext) == RedirectionController)
     {
         return(null);
     }
     return(NeedRedirection(filterContext));
 }