Here I am gong to get json Array from Appsettings.json
"RestrictedFunctionality": {
"UserRoleId": 2,
"RestrictedMenu": [
{
"name": "menu1"
},
{
"name": "menu2"
},
{
"name": "More",
"subMenu": ["submenu1" ]
}
],
"AllMenu": [
{
"name": "menu1"
},
{
"name": "menu2"
},
{
"name": "menu3"
},
{
"name": "menu4",
"subMenu": [ "submenu1", "submenu2", "submenu3", "submenu4"]
}
]
Here I am getting All menus and Restricted Menus.
var listOfRestrictedMenu = _restFunc.Value.RestrictedMenu;
var listOfallMenu = _restFunc.Value.AllMenu;
For getting above list I am using configuration. I have create class
public class RestrictedFunctionality
{
public List<Menu> RestrictedMenu { get; set; }
public List<Menu> AllMenu { get; set; }
}
Menu is a class which is have name, and sub menu
public class Menu
{
public string name { get; set; }
public List<string> subMenu { get; set; }
}
For the configuration I have added below code in startup
public void ConfigureServices(IServiceCollection services)
{
services.Configure<RestrictedFunctionality>(Configuration.GetSection("RestrictedFunctionality"));
services.AddMvc(options =>
{
options.Filters.Add(new CustomExceptionFilterAttribute());
options.Filters.Add(new CustomActionFilter());
});
services.AddSession();
services.AddHttpContextAccessor();
}
here When logged as a Administrator I have to get AllMenus. When I logged as Normal User. I have to get a Restricted list of Menu. For this purpose I create a allowedMenu by remove menus from AllMenu which are in the RestrictedMenu .
The Problem is When i logged as a normal user. allowedMenu are coming properly. After that when i logged as a administrator. Same allowedMenu is coming. here I am getting some json datawhich (which are allowed before) from app setting