Separate Features by Role in ASP.NET MVC

I am looking for an elegant pattern to solve this problem:

I have multiple user roles on my system and for many of my controller actions I need to deal with slightly different data.

For example, take

/Users/Edit/1

      

This allows you to Moderator

edit the email address user

, but Administrator

to change the user's email address and password.

I need a construct to separate two different bits of action code for GET

and POST

.

The solutions I've come up with so far:

  • Switching inside each method, however it doesn't help when I want different model arguments in POST :(
  • A custom controller factory that selects UsersController_ForModerators

    and UsersController_ForAdmins

    instead of just UsersController

    from the controller name and the current custom role
  • Custom action invoker that selects a method Edit_ForModerators

    similar to above
  • Have an IUsersController and register another implementation of this in my IoC container as a named Role based instance
  • Create a controller implementation at runtime using the Castle DynamicProxy function and apply methods to those of the role-playing implementations

I prefer the named route of the IoC atm instance as that means all my urls / routing will work without issue.

Ideas? Suggestions?

+2


a source to share


1 answer


Oh, no answers. Here's my attempt at an IoC approach, I think I'll be with that if anyone else has other ideas.



Logic separation logic based on user role in ASP.NET MVC

0


a source







All Articles