Something really bothers me about the way authorization tends to be done with roles in ASP.NET MVC.
The way it is normally done is that you have a Users table and a Roles table. A User can have many Roles.
Then you decorate your controllers/actions with an authorize attribute saying which roles you want to allow access to the controller/action:
[Authorize(Roles = "Admin")]
public ActionResult AdminOnlyAction()
{
}
The problem with this is that your code is reliant on data within the database.
Obviously you could, at application start, seed your database with the roles needed if they're not present but there's still a fragile dependency on the data in the database (e.g. it could be deleted, renamed, etc. etc.).
Having an enum or similar with the Role levels in instead of storing them in the database seems reasonable but still leaves me with a sour feeling.
Is there an elegant alternative which I've not hit upon?