After user authentication I'm supposed to change the user menu based on the roles of the user.
To do this, I created a service which fetched the menu the user is expected to see:
- public List
LoadCompleteMenuRole(string role) - {
- List
resultList = null; - var menuHeaders = LoadMenuHeadersForTheGivenRole(role);
- if (menuHeaders != null && menuHeaders.Count > 0)
- {
- resultList = new List
(); - foreach (var menuHeader in menuHeaders)
- {
- var menuStructure = new MenuStructure
- {
- MenuName = menuHeader.HeaderName,
- Caption = menuHeader.Caption
- };
- var menuDetails = LoadMenuDetailsForTheGivenHeader(menuHeader.Id);
- if (menuDetails != null && menuDetails.Count > 0)
- {
- menuStructure.MenuElements = new List
(); - foreach (var menuDetail in menuDetails)
- {
- var menuElement = new MenuElement
- {
- ElementName = menuDetail.DetailName,
- ElementCaption = menuDetail.Caption,
- Destination = menuDetail.Destination
- };
- menuStructure.MenuElements.Add(menuElement);
- }
- }
- resultList.Add(menuStructure);
- }
- }
- return resultList;
- }
My problem? Where do I implement the service so the menus get loaded in every razor page I create?

Farhan AhmedPosted Aug 28, 2020, 11:52 AM