0

I finally got my MVC 4 application all set up with SimpleMembership, but now have run into a new problem. I have a menu system (in a sidebar) that gives users access to various functionality throughout the app. I recently realized that, in order to be somewhat user-friendly, I need to disable or remove various menu links based on roles. So I set up a role system and a relationship to these menu links, which works perfectly. However, the "basic site access" role should not have access to all of the links in the menu (and their corresponding controllers/actions). Previously, I had given site access by simply applying the Authorize attribute globally, via my filter config:

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
    filters.Add(new AuthorizeAttribute());
}

Now I've figured out that, in order to control "basic" access to the app, I would need to add individual Authorize attributes at the action level (with the "admin" role having full access). While this is fine, albeit somewhat annoying, it doesn't seem very scalable. What if my client adds a new role through the administration interface and wants to control access to various tasks? I have already coded the menu system to disable links dynamically, based on what roles have access to which tasks. But there's no way (that I know of) to dynamically apply different roles to the Authorize attribute.

Though I've read about why SimpleMembership may not be the bee's knees, I've just finished migrating from ASP.NET Membership (which had serious shortcomings of its own), and I certainly do not want to roll my own user/role management system. Has anyone successfully implemented something to handle this scenario?

AJ.
  • 16,368
  • 20
  • 95
  • 150

1 Answers1

2

You should definitely take a look at Fluent Security if you have a lot of controllers/actions that you don't want to decorate with annotations.

It allows all authorisation to be handled from Global.asax. It's well documented and there's a good tutorial on it here.

MattSull
  • 5,514
  • 5
  • 46
  • 68
  • I had never heard of this, but it looks very promising. Thanks! I'm going to leave this question open for a bit to see if anyone else wants to weigh in. – AJ. Mar 27 '13 at 14:04
  • Did Fluent Security meet your requirements? – MattSull Apr 02 '13 at 12:04
  • 1
    Sorry, I haven't had time to implement it yet! I will certainly post again when I get the chance to play with it. – AJ. Apr 02 '13 at 14:37
  • It's been a while and the link is dead now, found [this on github](https://github.com/kristofferahl/FluentSecurity/wiki) – Lucas Palma Stabile Aug 21 '17 at 18:56