Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

IsVisible property of MenuItemDefinition is not working based on current session value #6592


User avatar
0
razkhan78 created
public class AppNavigationProvider : NavigationProvider
    {
        public const string MenuName = "App";
        public const string MenuTopName = "AppTop";

        private readonly IAbpSession session;

        public AppNavigationProvider(IAbpSession session)
        {
            session = session;
        }
public override void SetNavigation(INavigationProviderContext context)
        {
            var menu = context.Manager.Menus[MenuName] = new MenuDefinition(MenuName, new FixedLocalizableString("Main Menu"));
            menu
                .AddItem(new MenuItemDefinition(
                        AppPageNames.Host.Dashboard,
                        L("Dashboard"),
                        url: "App/HostDashboard",
                        icon: "flaticon-line-graph",
                        requiredPermissionName: AppPermissions.PagesAdministrationHostDashboard,
                        featureDependency: new SimpleFeatureDependency(true, AppFeatures.EnableTracking),
                        isVisible: (session.MultiTenancySide != MultiTenancySides.Host)
                    )
    }
    }
public override void PreInitialize()
        {
            Configuration.Navigation.Providers.Add<AppNavigationProvider>();
        }

We are working on creation of menu dynamically. in MenuItemDefinition there is property isVisible that show/hide menu in the web app we have use session based condition in that.

Our problem is that , when app is started this menu is register using PreInitialize() method. when it goes to AppNavigationProvider class , session value is (session.MultiTenancySide = "Host") because session is null when app is startup. on that bases whole menu item's visible property is set to false , and that menu will not shown to any user, either user is host user or tenant user

Surprisingly featureDependency works dynamically for every user.

could you please help me to solve this issue?

Thanks


3 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    When you create a MenuItemDefinition object, its isVisible property is already determined.

    If you want to control it dynamically, you can override the INavigationManager.

  • User Avatar
    0
    razkhan78 created

    Could you please show me how can i override INavigationManager and use isvisible property with session variable ?

  • User Avatar
    0
    maliming created
    Support Team

    Sorry, you can try to override the IUserNavigationManager and then evaluate the UserIdentifier when populating the menu to modify the isVisible property.

    https://github.com/aspnetboilerplate/aspnetboilerplate/blob/e0ded5d8702f389aa1f5947d3446f16aec845287/src/Abp/Application/Navigation/UserNavigationManager.cs#L51

    https://github.com/aspnetboilerplate/aspnetboilerplate/blob/e0ded5d8702f389aa1f5947d3446f16aec845287/src/Abp/Application/Navigation/UserNavigationManager.cs#L100

    Replacing Built-In Services: https://aspnetboilerplate.com/Pages/Documents/Startup-Configuration#replacing-built-in-services