【发布时间】:2014-06-23 19:25:51
【问题描述】:
介绍问题
我最近了解到,调用 ApiController Action 会触发 DelegatingHandler 的 SendAsync 方法,而调用 vanilla Controller Action 不会触发它。
搜索和研究
我查看了 Web Api,并了解到它包含 HttpMessageHandler,它是 DelegatingHandler 类的父级。这使我相信 HTTP 消息处理程序通常仅作为 Web API 管道的一部分执行。
另外,Http Message Handlers run before Url Routing,因此在 Web API 和 MVC 管道之间进行选择的可能不是 URL 路由。
...考虑使用动作过滤器而不是消息处理程序[因为]动作过滤器 在执行 URI 路由后运行。
问题
-
HttpMessageHandlers是 ASP.NET Web API 的一部分,而不是 ASP.NET MVC 的一部分吗? - 什么是 MVC 中的
HttpMessageHandler等价物(图中的EQUIVALENT)? - 是什么导致请求遵循 Web API 管道(图中的FORK)?
- Web API 请求与 MVC 请求有根本不同吗?
我的感觉是这样的,但请纠正我。
Request from Client
|
IIS
|
ASP.NET
|
HttpApplication.BeginRequest
|
et cetera
|
HttpApplication.MapRequestHandler - is this what does the routing?
|
FORK
/ \
/ \
/ \
/ \
/ \
**Web API** **MVC**
| |
HttpControllerRouteHandler MvcRouteHandler
| |
HttpControllerHandler |
| |
HttpMessageHandlers EQUIVALENT?
i.e. |
DelegatingHandlers |
incl. |
HttpServer |
CustomHandlers |
HttpRoutingDispatcher |
HttpControllerDispatcher |
有用的链接
【问题讨论】:
标签: c# asp.net asp.net-mvc asp.net-web-api