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" }));
}
}
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" }));
}
}