第4章:ASP.NET Core HTTP介绍

学习分享 丨作者 / 郑 子 铭 丨公众号 / DotNet NB / CloudNative NB

任务22:课程介绍

  • 1.HTTP 处理过程

  • 2.WebHost 的配置与启动

  • 3.Middleware 与管道

  • 4.Routing MiddleWare 介绍

任务23:Http请求的处理过程

任务24:WebHost的配置

  • 1.覆盖配置文件

  • 2.更改启动URL

  • 3.IHostingEnvironment

  • 4.IApplicationLifetime

  • 5.dotnet watch run

settings.json

Program.cs

Startup.cs

启动HelloCore,输出结果

Program.cs

Startup.cs

设置应用程序参数

启动HelloCore,输出结果

任务25:IHostEnvironment和 IApplicationLifetime介绍

Startup.cs

启动HelloCore,输出结果

Startup.cs

启动HelloCore,输出结果

我心中的ASP.NET Core 新核心对象WebHost(一):

http://www.jessetalk.cn/2017/11/11/aspnet-core-object-webhost/#comment-194arrow-up-right

我心中的ASP.NET Core 新核心对象WebHost(二):

http://www.jessetalk.cn/2017/11/14/aspnet-core-object-webhost-build/arrow-up-right

任务26:dotnet watch run 和attach到进程调试

New Terminal

F5 Start Debug

在csproj 的 ItemGroup 添加引用

New Terminal

修改代码保存后会自动重启

浏览器刷新即可看到更新结果

attach到进程调试

任务27:Middleware管道介绍

  • 1.Middleware 与管道的概念

  • 2.用 Middleware 来组成管道实践

  • 3.管道的实现机制(RequestDelegate 与 ApplicationBuilder)

startup.cs

启动项目,输出结果

访问 https://localhost:5001/taskarrow-up-right

任务28:RequestDelegate管道实现思路

  • 1.RequestDelegate

  • 2.ApplicationBuilder:多个RequestDelegate拼接

任务29:自己动手构建RequestDelegate管道

新建一个控制台程序

新建一个类RequestDelegate.cs

新建一个类Context.cs

在任何一个Middleware可以结束管道

任务30:RoutingMiddleware介绍以及MVC引入

访问 https://localhost:5001/actionarrow-up-right

使用UseRouter方法2

访问 https://localhost:5001/actionarrow-up-right

RountingMiddleware介绍

Last updated