Feedback on ASP.NET Web API

Execution Order of Mvc4 WebApi Action Filters

There is no way to forecast the execution order of WebApi Action Filters. It changes randomly each time the code is changed. It would be nice to have an integer property to control the order like in normal Mvc controllers, but also respecting the order they are put on the action method would be acceptable

215 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Francesco AbbruzzeseFrancesco Abbruzzese shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    4 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • JD ConleyJD Conley commented  ·   ·  Flag as inappropriate

        I had to develop a custom way to do this using the IFilterProvider. I use a filter to read authentication info from request headers and spin up the principal/identity. Additionally I have an audit filter that does a custom log of every request, and use the AuthorizeAttribute everywhere. These have to go in the right order or Bad Things happen.

      • Francesco AbbruzzeseFrancesco Abbruzzese commented  ·   ·  Flag as inappropriate

        Complete control over execution order can be achieved in the same way as with mvc controllers filters, that is through an integer Order property.

      • Glenn BlockGlenn Block commented  ·   ·  Flag as inappropriate

        Francesco Abbruzzese: How would you like expect ordering to be handled across global and per controller filters?

      • Francesco AbbruzzeseFrancesco Abbruzzese commented  ·   ·  Flag as inappropriate

        Please notice that each filter takes as input the output of the prevously executed filter, and we all know that the order of code execution do matter! So the way at moment filters work...imply that in 90% of cases it is not possible to use more than one filter! The remainder of code must be moved back in the controller.

      Feedback and Knowledge Base