Base solution for your next web application
Open Closed

Dynamic Navigation #471


User avatar
0
carelearning created

Hello,

We have a need to have the left navigation bar render differently based on features and permissions per tenant. For example we added this to AppNavigationProvider.cs,

if (_featureChecker.IsEnabled(IndividualConstants.FeatureName)) {
	context.Manager.MainMenu.AddItem(new MenuItemDefinition(
    	PageNames.App.Tenant.Individual,
    	L("Tenants"),
    	url: "tenant.individual",
    	icon: "icon-users"));
}

However, we receive the following error: FeatureChecker can not get a feature value by name. TenantId is not set in the IAbpSession!

Is there a way to dynamically generate navigation based on features and permissions? We were thinking about declaring the menu items in the client. Do you have any advice or know of any pitfalls?

careLearning-Bill


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

    Hi,

    MenuItem has properties for that. You can change your menu definition code like that:

    context.Manager.MainMenu.AddItem(new MenuItemDefinition(
           PageNames.App.Tenant.Individual,
           L("Tenants"),
           url: "tenant.individual",
           icon: "icon-users"),
           featureDependency: new SimpleFeatureDependency(PageNames.App.Tenant.Individual)
    );
    

    And remove your manual if condition. It will automatically check the feature dependency per tenant. For permissions, there is a also a requiredPermissionName property. See docs for more: <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Navigation">http://www.aspnetboilerplate.com/Pages/ ... Navigation</a>

    More info for your case: _featureChecker.IsEnabled can not work in AppNavigationProvider since these code is not executed in Tenant context. It's executed on application initialization (independent of any tenant).

  • User Avatar
    0
    carelearning created

    Thank you very much your reply!

    We have implemented the code you posted and it works great!

    Thank you again for your hard work.

    careLearning-Bill

  • User Avatar
    0
    hikalkan created
    Support Team

    You're welcome :)