Is there any general rule of thumb / pattern people have/should use to implement Role-based content views? In our project we have current folder structure similar to the one below (all content views).
We have two types of users. Regular users can access/manage the “campaigns” they own. Administrative users have access to ALL “campaigns” across all users.
For regular users, Report1,Report2,etc.are fine but for admin users we’d like to have a different view for each route:
Seems we could go about this different ways:
- Inside of each razor view, check the role and only render applicable content / js – would get messy to maintain.
- Break each view into separate “partial” views (Report1Partial.cshtml, AdminReport1Partial.cshtml) and check the role in the view and render applicable partial. Less messy.
- Create new request dto / service implementations, move the views inside the “Views” folder and control the view rendered in the service.
- Go back to MVC Controller/View(s)
- Keep it simple and just provide different routes for content pages that checks for required roles: (Admin/Dashboard/Report1.cshtml, etc)