Using the Authorize atribute

Topics: Web Api
Oct 6, 2011 at 9:20 PM

How can i use the MVC [Authorize] Attribute with WebApi

Oct 6, 2011 at 10:01 PM

You cannot use MVC's [Authorize] attribute directly.

However, it is not hard to have a similar behavior with operation handlers.

Take a look at:

https://github.com/pmhsfelix/WcfWebApi.Preview5.Explorations/blob/master/WcfWebApi.Preview5.Explorations.SelfHostedDemos/BasicAuthenticationWithHttpsDemo.cs (note the ".CheckAuthorization();" on the configuration)

https://github.com/pmhsfelix/WcfWebApi.Preview5.Explorations/blob/master/WcfWebApi.Preview5.Explorations.Common/AuthorizeOperationHandler.cs

HTH

Pedro