Hi;
I need help in displaying a set of menu items for public(anyone who enters the site) and the rest of menu items when users are authenticated.
Is it possible?
Thanks
You can set permissions for which users can see various menu items in the navigation.cs files - use the "Permission" parameter within the NavigationLink.
Example:
[assembly: NavigationLink(int.MaxValue, "Menu/Menu Item", typeof(MyPages.xyzController), icon: "fa fa-clipboard", Permission=xyzModule.PermissionKeys.Admin)] // replace xyzModule.PermissionKeys.Admin with your permission string constant or literal such as "Module:Admin"
I haven't tried removing permissions from menu items altogether but would guess that providing an empty string for the permissions parameter would achieve that.
If you want unauthenticated users to be able to access the site, you will also need to make sure that your default page does not have the [PageAuthorize] attribute on it's controller class.
Obviously you will need to be careful what data you expose by doing this and make sure you have appropriate permissions on your xyzRow entities etc.
@sjcdtm
Thank you for the response
I have already set permission to xxRow.cs so that will will handle permission for authenticated users. I am thinking of conditionally allowing users to have to menus:
If (anyuer.authorized==true)
{
The example that I gave above allows you to override the permission that is inherited from the xyzRow for the menu items (assuming you mean the standard navigation menus).
If the user does not have the permission specified in the NavigationLink, the menu item does not appear. You will find that non-authenticated users will be redirected to the login page if you have [PageAuthorization] attribute on the default page controller though.
If you want to be able to change the menus in code as your example above, this can be achieved using Dynamic Navigation, there are a few examples of this such as in #4346
@ms4hafiz
You might also want to check out the WIKI
https://github.com/volkanceylan/Serenity/wiki/UI:-Dynamic-navigation-items
Most helpful comment
@ms4hafiz
You might also want to check out the WIKI
https://github.com/volkanceylan/Serenity/wiki/UI:-Dynamic-navigation-items