0

In my API's I am extending a custom class (myClass) which extends ApiController.

What I want to do is in the constructor for myClass, compare two values, and if they don't match, then kill the process. Meaning I don't want the functions in the API to actually get hit.

I'd like to return HttpStatusCode.Forbidden but I don't want to have to modify existing API functions to check a value that could be set by the controller.

I can't seem to find a good way to kill the request in the constructor and return the HttpStatusCode without blocking access to the rest of the API if it's supposed to continue to the requested API function.

Is there a relatively simple approach that could work for this?

Tony Shepherd
  • 115
  • 1
  • 8
  • 3
    You are looking for [action filters](http://stackoverflow.com/questions/33423554/intercept-all-webapi-calls-before-the-route-matching-occurs?lq=1). – Jasen Dec 29 '15 at 18:08

1 Answers1

1

you can set Authentication Filter to check that. check more details here

Anik Saha
  • 4,313
  • 2
  • 26
  • 41