.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();
        }

 

posted @ 2020-01-31 20:51  龍☆  阅读(623)  评论(0)    收藏  举报