I have web.config entries as shown below. This is for controlling access of users in various roles to various pages.
Admin screen can be access by Hiring Manager and CRM1 Logs screen can be access by CRM3 and Transferee
add key="AdminScreenRoles" value ="Hiring Manager,CRM1"
add key="LogsScreenRoles" value ="CRM3,Transferee "
In future new roles can be given access to Admin screen. Also new pages may be introduced.
I need to ensure that the current user has access to at least one of the pages in the config file. I have the following code. It works. Is there any better/concise/scalable code for this functionality?
List<string> authorizedRolesForAdmin = new List<string>((ConfigurationManager.AppSettings["AdminScreenRoles"]).Split(','));
List<string> authorizedRolesForLogs = new List<string>((ConfigurationManager.AppSettings["LogsScreenRoles"]).Split(','));
if ((authorizedRolesForAdmin.Contains(roleName)) || (authorizedRolesForLogs.Contains(roleName)))
{
//Has access to at least one page
}
REFERENCE: