Created
January 29, 2014 18:51
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// The RolesAttribute extends the <see cref="AuthorizeAttribute"/> by allowing you to just assign a list of strings. | |
/// </summary> | |
public class RolesAttribute : AuthorizeAttribute | |
{ | |
public RolesAttribute(params string[] roles) | |
{ | |
if (roles == null) | |
throw new ArgumentNullException("roles", "roles can not be a null reference."); | |
Roles = string.Join(",", roles); | |
} | |
} | |
/* | |
Usage: | |
[Roles("Administrator", "Management")] | |
public class SecretController : Controller { | |
} | |
If you store your roles in a separate class, and make them const's, you can also do: | |
[Roles(Role.Administrator, Role.Management)] | |
public class SecretController : Controller { | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment