.Net Core HTTP请求管道配置--自定义中间件
中间件参考项目:
https://github.com/aspnet/basicmiddleware
在HTTP的请求过程中,可以对请求做各种操作。
比如根据不同的http header,返回不同的信息,或者更改response;
根据不同的请求path,做不同的处理
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } //当请求/HelloPath时的响应 app.Map("/HelloPath", a => a.Run(async context => { await context.Response.WriteAsync($"Hello HelloPath"); })); app.UseHttpsRedirection(); app.UseMvc(); }
好的程序员,他们删掉的代码,比留下来的还要多很多。