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的宿主时, ...
随机推荐
- synchronized同步方法
“非线程安全”其实会在多个线程对同一个对象中的实例变量进行并发访问的时候产生,产生的后果是脏读,也就是取到的数据是被更改过的.而“线程安全”就是以获得的实例变量的值是经过同步处理的,不会出现脏读的现象 ...
- Ubuntu远程登录服务器--ssh的安装和配置
ssh是一种安全协议,主要用于给远程登录会话数据进行加密,保证数据传输的安全. 安装ssh sudo apt-get update sudo apt-get install openssh-serve ...
- bootstrap之辅助类
类 描述 .pull-left 元素浮动到左边 .pull-right 元素浮动到右边 .center-block 设置元素为 display:block 并居中显示 .clearfix 清除浮动 . ...
- Linux系统修改编码(转)
Windows的默认编码为GBK,Linux的默认编码为UTF-8.在Windows下编辑的中文,在Linux下显示为乱码.为了解决此问题,修改Linux的默认编码为GBK.方法如下: 方法1: vi ...
- mysql 内连接原理
- Linux环境下安装Redis并完成测试(已验证)
准备工作: 本人测试环境:Win7 xshell远程登录Linux Linux: ubuntu 软件包:redis-3..2.6.tar.gz (Linux下redis安装包) =========== ...
- htop 分析 进程对资源的消耗
[root@d ~]# htop -hhtop 2.2.0 - (C) 2004-2018 Hisham MuhammadReleased under the GNU GPL. -C --no-col ...
- importlib应用 - django
背景 仿django的中间件的编程思想 用户可通过配置,选择是否启用某个组件/某个功能,只需要配置 eg:报警系统,发邮件,发微信 ... ( 根据字符串导入模块, 利用反射找到模块下的类,实例化.执 ...
- PostgreSQL数据库的安装与PostGIS的安装(转)
原文:http://lovewinner.iteye.com/blog/1490915 安装postgresql sudo apt-get install postgresql-9.1 postgre ...
- sshd:root@notty解决方法
sshd:root@notty解决方法 [复制链接]--http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=2050551 cat /e ...