本文介绍了ASP.NET Core 中间件与过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

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

解决方案

在第 9 频道上有一个关于此的视频:因此,如果您不需要 MVC 的上下文(假设您关心流程和执行,例如响应标头某些预路由机制等),则使用中间件.
但是,如果您需要 MVC 的上下文并且想要针对操作进行操作,那么请使用过滤器.

After reading about ASP.NET Core middleware, I am confused about when I should use filters and when I should use middleware as they seem to achieve the same goal.When should middleware be used instead of filters?

解决方案

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.

这篇关于ASP.NET Core 中间件与过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 16:28