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

Menu with CustomAuthorizeAttribute

3 Answers 67 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Shane
Top achievements
Rank 1
Shane asked on 13 Jul 2011, 05:23 PM
I'm having the same issue as Ben was in this post: http://www.telerik.com/community/forums/aspnet-mvc/general/the-menu-control-and-authorizecore.aspx#1717973

The only difference is that I'm not using a sitemap to build the menu - instead the menu is hardcoded into the layout.
I'm seeing the same behavior where if one of the actions in the menu has my CustomAuthorizeAttribute, AuthorizeCore is never being called.  The menu option is simply hidden.
Here is the code I'm using for the menu:

@{ 
    var navAuthorization = Telerik.Web.Mvc.Infrastructure.DI.Current.Resolve<Telerik.Web.Mvc.Infrastructure.INavigationItemAuthorization>();
    Html.Telerik()
        .Menu()
        .Name("Menu")
        .Items(menu =>
        {
            menu.Add().Text("Home").Url("~/");
            menu.Add().Text("External System Connections").Action("Listing", "ExternalSystem");
            menu.Add().Text("Agencies").Action("Listing", "Agency");
            menu.Add().Text("Users").Action("Search", "User");
            menu.Add().Text("Devices").Action("Search", "Device");
            menu.Add().Text("Chat").Action("Listing", "DistributionList");
            menu.Add().Text("Configuration").Action("Listing", "Configuration");
            menu.Add().Text("Annunciator").Action("Listing", "Annunciator");
            menu.Add().Text("Log out").Action("LogOut", "Home");
        })
        // Hide top level menus if none of the sub menus are accessible
        .ItemAction(item =>
        {
            bool hasAccessible = true;
            foreach (var children in item.Items)
            {
                hasAccessible = false;
                if (children.IsAccessible(navAuthorization, ViewContext))
                {
                    hasAccessible = true;
                    break;
                }
            }
            item.Visible = hasAccessible;
        })
        .Render();
}

I'm using the latest version of the controls (7/12/2011)

3 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 14 Jul 2011, 12:04 PM
Hello Shane,

 
Could you please send the implementation of your custom authorization attribute? It will be really helpful if you can send us a simple test project which replicates the issue. Thus I will be able to observe the behavior locally and advice you further.

Kind regards,
Georgi Krustev
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Ann Lewkowicz
Top achievements
Rank 1
answered on 14 Nov 2011, 06:29 PM
I'm having this same problem.  Did anything come of this issue?

Many thanks,

Ann L. 
0
Ann Lewkowicz
Top achievements
Rank 1
answered on 14 Nov 2011, 06:54 PM
I just discovered that the root of the problem (in my case at least) was having a constructor declared in my authorization attribute.  I had one that took a single parameter.  Once I removed it and started passing the custom info it needed through named parameters, the problem went away.

I wonder if custom authorization attributes all have to have parameterless constructors?  In any case, that made the difference. 
Tags
General Discussions
Asked by
Shane
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Ann Lewkowicz
Top achievements
Rank 1
Share this question
or