Async action filter in MVC 4

后端 未结 3 505
死守一世寂寞
死守一世寂寞 2020-11-29 10:22

I have an action filter that when used in certain specific conditions has to perform a web service call to ensure that the current state is valid. This initially seemed like

3条回答
  •  难免孤独
    2020-11-29 10:48

    You cannot have async filters, but you can have async event handlers.

    An async event handler can do the heavy async work, write to HttpApplication.HttpContext.Items, and then your sync filter can post-process or verify the results.

    You can either register event handlers in Global.asax.cs, or create and register a HTTP module.

    (All filters are executed between the PreRequest and PostRequest events.)

提交回复
热议问题