Skip to content

Instantly share code, notes, and snippets.

@wcabus
Created January 29, 2014 18:51
/// <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