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)
-
0
When you create a MenuItemDefinition object, its isVisible property is already determined.
If you want to control it dynamically, you can override the INavigationManager.
-
0
Could you please show me how can i override INavigationManager and use isvisible property with session variable ?
-
0
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