Reputation: 12703
I tried to implement my own AuthorizeAttribute for my REST API that I've built with the WCF Web API Preview 6.
Unfortunately only the constructor gets called, but non of the methods. Am I missing something with the registration?
[BasicHttpAuthorize]
[WebGet(UriTemplate = "")]
public IEnumerable<Supertext.API.Order> Get()
{
And this is my super simplified code.
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class BasicHttpAuthorizeAttribute: AuthorizeAttribute
{
public BasicHttpAuthorizeAttribute()
{
}
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
return true;
}
public override void OnAuthorization(AuthorizationContext filterContext)
{
//do the authorization
}
}
But as I said, neither the AuthorizeCore nor the OnAuthorization method is ever called.
Any ideas?
Upvotes: 0
Views: 1418
Reputation: 1
I was able to complete the implementation of above without HttpOperationHandler
but inheriting from System.Web.Http.AuthorizeAttribute
instead of the System.Web.Mvc.AuthorizeAttribute
. Maybe once both the MCV and former WCF teams are fully merged the two implementations will come to the center, but for now, a namespace change helped out a ton!
See ref: Custom MVC AuthorizeAttribute for ASP.NET Web API
Upvotes: 0
Reputation: 12703
Since using the AuthorizeAttribute does not work with the WCF Web API, I came up with my own solution.
I've built a custom HttpOperationHandler and combined it with an Attribute, so I get a similar functionality as the MVC AuthorizeAttribute.
The result is here:
http://remy.supertext.ch/2012/02/basic-authentication-with-wcf-web-api-preview-6/
Upvotes: 0
Reputation: 1038730
The AuthorizeAttribute
and action filters in general are ASP.NET MVC specific artifacts. They have nothing to do with WCF. Decorating a WCF operation contract with it won't have much effect.
Upvotes: 3