Reputation: 3082
I have been trying to implement role based security on my MVC4 application so that some controller actions are blocked to non admin members. I have found this information page on MSDN: http://msdn.microsoft.com/en-us/library/5k850zwb%28v=vs.100%29.aspx
Can someone tell me where would be the best place to great the admin group itself using the following line:
Roles.CreateRole("Admin");
I know I want to check my user database table and check the IsAdmin column on the Home Controller Index but I am not sure about where to create the actual Admin role itself. Any help would be greatly appreciated.
Upvotes: 1
Views: 528
Reputation: 18967
Just add it manually to webpages_Roles
table of your database.
If you want to do it programatically, add it to the InitializeSimpleMembershipAttribute.cs
file into the Filters
folder, below the folloing line:
WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
// here it REALLY is...!
if (!Roles.RoleExists("Admin"))
Roles.CreateRole("Admin");
Upvotes: 1