Create your own attribute and get from AuthorizeAttribute. Then override the AuthorizeCore method and implement your own logic, checking for a role that contains a space.
An example might be something like this:
public class CustomAuthAttribute : AuthorizeAttribute
{
private readonly IUserRoleService _userRoleService;
private string[] _allowedRoles;
public CustomAuthAttribute(params string[] roles)
{
_userRoleService = new UserRoleService();
_allowedRoles = roles;
}
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
var userName = httpContext.User.Identity.Name;
var userRoles = _userRoleService .GetUserRoles(userName);
return _allowedRoles.Any(x => userRoles.Contains(x));
}
}
Using
[CustomAuth("role withspace","admin")]
public ActionResult Index()
{
}
source
share