0

I've been meddling a bit with Authorization for a while and found a few pages that helped me override the default methods. However, it seems that I cannot get the attribute to work. I debug my project with Visual Studio 2013 and yet it still does not stop at the breakpoint where the Authorize method is redifined. This wouldn't be an issue if the web services worked after placing the [Authorize] over the class or even individual methods. I've tried them all yet it seems that everything it returns is 401 Unauthorized. It doesn't even enter the desired Web service either. Here is a few samples to explain my problem:

[Authorize]
[RoutePrefix("api/MyWS")]
public class MyWSController : ApiController
{
    private Test_UnitOfWork unitOfWork = new Test_UnitOfWork();

    [Route("Get"), HttpGet]
    public IEnumerable<MyWS> Get()
    {
        return unitOfWork.MyWSRepository.Get().OrderBy(s => s.Name);
    }

Redefinition of OnAuthorization method

public class TokenValidationAttribute : System.Web.Http.AuthorizeAttribute
{
    public override void OnAuthorization(HttpActionContext actionContext)
    { ...

Controller calling the web service

MyWSlist = client.GetSync<IList<MyWS>>("MyWS");

I'd like to know what I'm doing wrong here, seeing as whenever I try to debug my project, I can't seem to enter the rewriten code at all, it just returns the Unauthorized error. I've also tried to rewrite the other methods but no dice. Regards

E.T.
  • 367
  • 5
  • 18
  • You can't add a breakpoint by default to an Authorize attribute, but see [How can I override the Authorize attribute so I can put a breakpoint on it](http://stackoverflow.com/questions/36140015/how-can-i-override-the-authorize-attribute-so-i-can-put-a-breakpoint-on-it) – stuartd Oct 04 '16 at 14:10

1 Answers1

3

I debug my project with Visual Studio 2013 and yet it still does not stop at the breakpoint where the Authorize method is redifined.

After overriding AuthorizeAttribute, you want to apply that to controller or action unless you configure as Global filter.

[TokenValidation]
public class MyWSController : ApiController
{
  ...
}

Or, am I missing something in your question?

Win
  • 61,100
  • 13
  • 102
  • 181
  • You are absolutely right, I feel like a massive idiot right now. Thank you for clearing my mind on this. – E.T. Oct 04 '16 at 14:17