asp.net core middleware vs filters

后端 未结 3 1721
星月不相逢
星月不相逢 2020-12-02 12:57

After reading about asp.net core middlware, I am confused when should I use filters and when should I use middlewares as they seem to achieve the same goal. When should midd

3条回答
  •  时光取名叫无心
    2020-12-02 13:35

    There is a video about this on channel 9: ASP.NET Monsters #91: Middleware vs. Filters. To summarize the video:

    The execution of request starts and we have a middleware, and another middleware, think of it like the "Russian dolls inside of dolls" and eventually the routing middleware kicks in and then request goes into the MVC pipline. So if you don't require the context of MVC (let's say you're concerned about flow and execution, like responding to headers some pre-routing mechanism, etc.) then use middlewares.
    But if you require the context of MVC and you want to operate against actions then use filters.

提交回复
热议问题