I have a ASP.NET MVC4 web application with tables users, roles and rolePrivileges
userid username password roleid] values: 1 user1 12345 3, 2 user2 12345 1, 3 user3 12345 2
[roleid, rolename ] values: 1 admin, 2 client, 3 guest, 4 ...
[Roleid, Action, GrantAccess] values: 1 /Home/Index Y 1 /Home/Settings Y 1 /Home/Dashboard Y 2 /Home/Index Y 2 /Home/Settings N 2 /Home/Dashboard Y 3 /Home/Index Y 3 /Home/Settings N 3 /Home/Dashboard N
I would like to achieve the following in ASP.NET MVC forms authentication:
A controller action should be dynamically granted denied access to a role , and if a user tries to access a controller action which the user is not granted access the application should signout.
1) I want to know the best way to achieve this since hardcoding the rolename like Authorize(Roles="admin")] will not work
2) I also have user specific settings which would need to be initialized on user log in ,in asp.net forms this was stored in session variables can the same be done using TempData in asp.net MVC is this is best practice?