ASP.NET Core 中间件与过滤器

2024-05-23

在阅读了 ASP.NET Core 中间件之后,我对何时应该使用过滤器以及何时应该使用中间件感到困惑,因为它们似乎实现了相同的目标。 什么时候应该使用中间件而不是过滤器?


9频道有一个关于此的视频:ASP.NET 怪物 #91:中间件与过滤器 https://channel9.msdn.com/Series/aspnetmonsters/ASPNET-Monsters-91-Middleware-vs-Filters。总结一下视频:

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. enter image description here 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.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ASP.NET Core 中间件与过滤器 的相关文章