Reputation: 693
I have this Custom Attribute (Custom MVC Authorization):
public class CustomAuthorizeAttribute : AuthorizationFilterAttribute
{
public string Users { get; set; } //its always null!
public override void OnAuthorization(HttpActionContext actionContext)
{
string user = Thread.CurrentPrincipal.Identity.Name.Split('\\')[1];
AdProxy AdProxy = new AdProxy();
if (!AdProxy.IsUserInGroup(user, Users))
{
actionContext.Response = new HttpResponseMessage(HttpStatusCode.Unauthorized);
}
}
}
I use it like this:
[CustomAuthorizeAttribute(Users = "Admin")]
But on debugging the value of "Users" is always null. Any idea?
Upvotes: 2
Views: 1236
Reputation: 6251
Try this:
public class CustomAuthorizeAttribute : AuthorizeAttribute
{ ... }
Upvotes: 0
Reputation: 449
If you are using .net Framework 4.5.1 change to 4.5 and it should work.
class CustomAuthorizeAttribute : AuthorizeAttribute
{
public string Users { get; set; }
public override void OnAuthorization(AuthorizationContext filterContext)
{
base.OnAuthorization(filterContext);
}
}
Upvotes: 1