MenuItem hide with custom FilterAttribute

2 posts, 0 answers
  1. Vitalii
    Vitalii avatar
    4 posts
    Member since:
    Mar 2013

    Posted 18 Mar 2013 Link to this post

    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)
                else filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Error", action = "AccessDenied" }));
  2. Georgi Krustev
    Georgi Krustev avatar
    3747 posts

    Posted 19 Mar 2013 Link to this post

    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!
Back to Top