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的更多相关文章

  1. ASP.NET Web API - 使用 Castle Windsor 依赖注入

    示例代码 项目启动时,创建依赖注入容器 定义一静态容器 IWindsorContainer private static IWindsorContainer _container; 在 Applica ...

  2. 【ASP.NET Web API教程】3.4 HttpClient消息处理器

    原文:[ASP.NET Web API教程]3.4 HttpClient消息处理器 注:本文是[ASP.NET Web API系列教程]的一部分,如果您是第一次看本博客文章,请先看前面的内容. 3.4 ...

  3. 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 ...

  4. 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 ...

  5. [整理]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 ...

  6. ASP.NET Web API与Owin OAuth:使用Access Toke调用受保护的API

    在前一篇博文中,我们使用OAuth的Client Credential Grant授权方式,在服务端通过CNBlogsAuthorizationServerProvider(Authorization ...

  7. 8 种提升 ASP.NET Web API 性能的方法

    ASP.NET Web API 是非常棒的技术.编写 Web API 十分容易,以致于很多开发者没有在应用程序结构设计上花时间来获得很好的执行性能. 在本文中,我将介绍8项提高 ASP.NET Web ...

  8. 推荐升级ASP.NET Web API 2

    ASP.NET Web API 使用很长时间了,期间也碰到不少问题,升级到WebAPI2后这些问题都解决了,稳定性方面也提升不少,所以推荐使用.碰到的问题是下面的2类: 1.multipart/for ...

  9. Self Host模式下的ASP. NET Web API是如何进行请求的监听与处理的?

    构成ASP.NET Web API核心框架的消息处理管道既不关心请求消息来源于何处,也不需要考虑响应消息归于何方.当我们采用Web Host模式将一个ASP.NET应用作为目标Web API的宿主时, ...

随机推荐

  1. LeetCode——Add Digits

    Description: Given a non-negative integer num, repeatedly add all its digits until the result has on ...

  2. Redis单机主从高可用性优化

    版权声明:本文由陈龙原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/127 来源:腾云阁 https://www.qclou ...

  3. Cookie/Session机制详解 <转>

    会话(Session)跟踪是Web程序中常用的技术,用来跟踪用户的整个会话.常用的会话跟踪技术是Cookie与Session.Cookie通过在客户端记录信息确定用户身份,Session通过在服务器端 ...

  4. 真机远程页面调试工具spy-debugger 3.x:集成weinre+AnyProxy,页面调试+抓包。调试生产HTTPS页面。

    .页面调试+抓包 2.操作简单 3.支持HTTPS. 4.spy-debugger内部集成了weinre.node-mitmproxy.AnyProxy. 5.自动忽略原生App发起的https请求, ...

  5. [SQL]批量 更改字符集脚本,批量查询约束,批量查询索引

    How to change collation of all database objects in SQL Server. Have you encountered a problem where ...

  6. java设计模式----迭代子模式

    顺序访问聚集中的对象,主要用于集合中.一是需要遍历的对象,即聚集对象,二是迭代器对象,用于对聚集对象进行遍历访问. 迭代子模式为遍历集合提供了统一的接口方法.从而使得客户端不需要知道聚集的内部结构就能 ...

  7. Vue 学习顺序

    起步: 1.扎实的 JavaScript / HTML / CSS 基本功,ES6 最好过一遍 2.通读官方教程 (guide) 的基础篇.不要用任何构建工具,就只用最简单的 <script&g ...

  8. java8新增的日期时间包

    Clock clock=Clock.systemUTC(); System.out.println("当前时刻为:"+clock.instant()); System.out.pr ...

  9. .net配置404错误页面

    如果你的网站出现一堆让人看不懂的报错,那么你就不是一个合格的程序员,也不是一个合格的站长. 下面的方面可以帮助你的网站远离让人头大的页面. 第一步:配置web.config 打开web.config, ...

  10. pandas的merge方法

    数据合并时可以使用merge方法,对两个dataFrame根据某一个series合并,这个方法非常好用,只要找到了合并的标准,新的数据就可以重构出来. 1.命令: pd.merge() on:列名,j ...