ASP.NET WEB API 2: HTTP MESSAGE LIFECYLE
https://www.asp.net/media/4071077/aspnet-web-api-poster.pdf
1.You can host Web API inside IIS or inside your own process (self-hosting).
2.The HTTP request message is first converted to an HttpRequestMessage object, which provides strongly typed access to the HTTP message.
3.HttpMessageHandler
3.1 Delegating Handler
3.2 HTTPRoutingDispatcher
3.3 HTTPControllerDispatcher
StepA:Create Api Controller
4.Controller
StepB: Select controller action
4.1 Authentication Filters
4.2 Authorization Filters
StepC:Model Binding
4.3 Action Filters 源码https://github.com/aspnet/AspNetWebStack/blob/master/src/System.Web.Http/Filters/ActionFilterAttribute.cs
StepE: Invoke Action -->这里有可能触发Exception Filters
StepD:Result Conversion
在看pdf的时候,还需要注意标准

实际使用中遇到的问题
使用Autofac进行构造函数注入,但是依赖api传递进来的参数。
之前使用的方案是,在ActionFilter中拿到controller以及api参数,然后手动调用resolve去实例化,本来需要构造函数注入的属性。
调整之后:(必须在DelegateHandler中解析,因为ActionFilter的执行,是在Controller实例化之后)
在DelegateHandler中解析参数,并存储。然后在Autofac的lambda注册的地方,委托那边直接OwinRequestScopeContext拿到参数。
var apiRequest = request.Content.ReadAsAsync<ApiRequest<dynamic>>().Result;
OwinRequestScopeContext.Current.Items["CountryCode"] = apiRequest.Header.OpCo;
扩展阅读
https://exceptionnotfound.net/the-asp-net-web-api-2-http-message-lifecycle-in-43-easy-steps-2/
http://rajeevdotnet.blogspot.com/2018/03/the-lifecycle-of-aspnet-web-api.html

http://www.cnblogs.com/shanyou/archive/2012/03/17/2404180.html

ASP.NET WEB API 2: HTTP MESSAGE LIFECYLE的更多相关文章
- ASP.NET Web API - 使用 Castle Windsor 依赖注入
示例代码 项目启动时,创建依赖注入容器 定义一静态容器 IWindsorContainer private static IWindsorContainer _container; 在 Applica ...
- 【ASP.NET Web API教程】3.4 HttpClient消息处理器
原文:[ASP.NET Web API教程]3.4 HttpClient消息处理器 注:本文是[ASP.NET Web API系列教程]的一部分,如果您是第一次看本博客文章,请先看前面的内容. 3.4 ...
- Custom Exception in ASP.NET Web API 2 with Custom HttpResponse Message
A benefit of using ASP.NET Web API is that it can be consumed by any client with the capability of m ...
- Lifecycle of an ASP.NET Web API Message
ASP.NET Web API, as we know now, is a framework that helps build Services over HTTP. Web API was int ...
- [整理]ASP.NET WEB API 2学习
目录 1 快速入门 1.1实例 1.1.1初识WEB API 2 1.1.2 Action Results 的改变 1.1.3 路由的新增特性 1.1.4 消息管道的变化 1.1.4.1 HttpMe ...
- ASP.NET Web API与Owin OAuth:使用Access Toke调用受保护的API
在前一篇博文中,我们使用OAuth的Client Credential Grant授权方式,在服务端通过CNBlogsAuthorizationServerProvider(Authorization ...
- 8 种提升 ASP.NET Web API 性能的方法
ASP.NET Web API 是非常棒的技术.编写 Web API 十分容易,以致于很多开发者没有在应用程序结构设计上花时间来获得很好的执行性能. 在本文中,我将介绍8项提高 ASP.NET Web ...
- 推荐升级ASP.NET Web API 2
ASP.NET Web API 使用很长时间了,期间也碰到不少问题,升级到WebAPI2后这些问题都解决了,稳定性方面也提升不少,所以推荐使用.碰到的问题是下面的2类: 1.multipart/for ...
- Self Host模式下的ASP. NET Web API是如何进行请求的监听与处理的?
构成ASP.NET Web API核心框架的消息处理管道既不关心请求消息来源于何处,也不需要考虑响应消息归于何方.当我们采用Web Host模式将一个ASP.NET应用作为目标Web API的宿主时, ...
随机推荐
- Request.getRequestURL
getRequestURI()就相当于你在写一个JSP页面的时候会有这样的东西"action='/WebRoot/xxx'"这个方法就是获得'/WebRoot/xxx',也就是说它 ...
- [黑金原创教程] FPGA那些事儿《数学篇》- CORDIC 算法
简介 一本为完善<设计篇>的书,教你CORDIC算法以及定点数等,内容请看目录. 贴士 这本教程难度略高,请先用<时序篇>垫底. 目录 Experiment 01:认识CORD ...
- 【BZOJ4372】烁烁的游戏 动态树分治+线段树
[BZOJ4372]烁烁的游戏 Description 背景:烁烁很喜欢爬树,这吓坏了树上的皮皮鼠.题意:给定一颗n个节点的树,边权均为1,初始树上没有皮皮鼠.烁烁他每次会跳到一个节点u,把周围与他距 ...
- 【BZOJ4559】[JLoi2016]成绩比较 动态规划+容斥+组合数学
[BZOJ4559][JLoi2016]成绩比较 Description G系共有n位同学,M门必修课.这N位同学的编号为0到N-1的整数,其中B神的编号为0号.这M门必修课编号为0到M-1的整数.一 ...
- 利用aspose-words 实现 java中word转pdf文件
利用aspose-words 实现 java中word转pdf文件 首先下载aspose-words-15.8.0-jdk16.jar包 引入jar包,编写Java代码 package test; ...
- Spring MVC 框架学习
一.spirng的简介 Spring是一个开源框架,它由Rod Johnson创建.它是为了解决企业应用开发的复杂性而创建的.Spring使用基本的JavaBean来完成以前只可能由EJB完成的事情. ...
- # 释放内存 filter_res_q_l = filter_res_q_l[-2048:] filter_res_a_l = filter_res_a_l[-2048:]
# 释放内存filter_res_q_l = filter_res_q_l[-2048:]filter_res_a_l = filter_res_a_l[-2048:]
- lampp and testrail
https://wyzx.testrail.net szllq2000 http://129.0.1.228/testrail/ http://docs.gurock.com/testrail-adm ...
- 解决Uploadify 3.2上传控件加载导致的GET 404 Not Found问题
http://www.uploadify.com/forum/#/discussion/7329/uploadify-v3-bug-unecessary-request-when-there-is-n ...
- India and China Origins---hdu5652(二分 + bfs)或者(并查集)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5652 题意: 很久以前,中国和印度之间并没有喜马拉雅山相隔,两国的文化交流很频繁.随着喜马拉雅山海拔逐 ...