I am having a problem with my custom attribute AuthorizeAttribute
public class ExplicitAuthorizeAttribute : AuthorizeAttribute { private readonly MembershipUserRole[] _acceptedRoles; public ExplicitAuthorizeAttribute() { } public ExplicitAuthorizeAttribute(params MembershipUserRole[] acceptedRoles) { _acceptedRoles = acceptedRoles; } protected override bool AuthorizeCore(HttpContextBase httpContext) {
I use it as follows:
[ExplicitAuthorize[(MembershipUserRole.Admin, MembershipUserRole.SuperAdmin)]
It works great for HttpGet and HttpPost to test my controllers and methods.
But when I use it in ApiController and make ajax calls, AuthorizeCore does not work, and I received a security violation.: /
My listing is as follows
[Flags] public enum MembershipUserRole { Admin= 1, SuperAdmin = 2 }
Does anyone know why my AuthorizeCore does not check in this context?
By the way, if I use
[Authorized(Roles ="Admin, SuperAdmin")]
It is well-tested, but I would like to have strong typed roles, so I use enums.
source share