This is a migrated thread and some comments may be shown as answers.

MenuItem hide with custom FilterAttribute

1 Answer 112 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Vitalii
Top achievements
Rank 1
Vitalii asked on 18 Mar 2013, 05:06 PM
I have necessary to auto hide menu items when current user have not access to this action
below I present my custom filter attribute, based on AuthorizeAttribute
As you can see, if user can't have rights to action, system redirect him to AccessDenied action
but menu item binded on action market with this action filter, rendered always
please help

public class PermissionOnEntityActionAttribute : AuthorizeAttribute
    {
         protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            var isAuthorized = base.AuthorizeCore(httpContext);
            if (!isAuthorized) return false;
          
            return securityModule.CurrentUserHasPermission(...);
        }

        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
            {
                base.HandleUnauthorizedRequest(filterContext);
            }
            else filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Error", action = "AccessDenied" }));
        }
    }

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 19 Mar 2013, 05:18 PM
Hello Vitalii,

 
The Kendo Menu hides menu items only if the AuthorizationContext.Result is of HttpUnauthorizedResult type. Hence you will need to create custom HttpUnauthorizedResult and navigate in it to desired custom view. Check this github repository for more information.

All the best,
Georgi Krustev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Menu
Asked by
Vitalii
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or