何时使用HttpMessageHandler和ActionFilter? [英] When to use HttpMessageHandler vs ActionFilter?

查看:71
本文介绍了何时使用HttpMessageHandler和ActionFilter?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这两个似乎有相似的目的.很高兴看到一些示例,何时使用彼此的优缺点,并指出主要的区别是什么.

It seems that these two have a similar purpose. It would be great to see some examples when to use one over the other, pros and cons, as well as point out what are the key differences.

推荐答案

他们之间的主要区别在于他们的关注点.信息处理程序适用于所有HTTP请求.他们执行功能HTTP中介.过滤器仅适用于分派给过滤器所在的特定控制器/动作已应用.

The major difference between their two is their focus. Message Handlers are applied to all HTTP requests. They perform the function of an HTTP intermediary. Filters apply only to requests that are dispatched to the particular controller/action where the filter is applied.

当您希望行为是适用于绝大多数请求.在以下情况下应使用过滤器它们仅适用于某些资源.

You should use MessageHandlers when you want the behaviour to be applied to the vast majority of requests. Filters should be used when they are only applicable to certain resources.

这篇关于何时使用HttpMessageHandler和ActionFilter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆