Non-string role names in ASP.NET MVC?

Posted by MikeWyatt on Stack Overflow See other posts from Stack Overflow or by MikeWyatt
Published on 2010-05-13T16:19:22Z Indexed on 2010/05/13 16:24 UTC
Read the original article Hit count: 255

Filed under:
|

ASP.NET MVC has good support for role-based security, but the usage of strings as role names is maddening, simply because they cannot be strongly-typed as enumerations.

For example, I have an "Admin" role in my app. The "Admin" string will now exist in the Authorize attribute of my action, in my master page (for hiding a tab), in my database (for defining the roles available to each user), and any other place in my code or view files where I need to perform special logic for admin or non-admin users.

Is there a better solution, short of writing my own authorization attribute and filter, that would perhaps deal with a collection of enumeration values?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about roles