zoukankan      html  css  js  c++  java
  • 02. Asp.Net Core 3.x 笔记 中间件

    中间件

    
        public class Startup
        {
            ....
    
            // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
            //配置Http请求管道
            public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
            {
                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                }
    
                app.UseRouting(); //路由中间件
    
                app.UseEndpoints(endpoints =>
                {
                    endpoints.MapGet("/", async context =>
                    {
                        await context.Response.WriteAsync("Hello World!");
                    });
                });
            }
        }
    
    

    端点 endpoint

    端点 就是http请求的Url的结尾那部分,这部分会被中间件进行处理

    路由中间件

    app.UseRouting(); //路由中间件

    端点中间件

    app.UseEndpoints 配置为使用MVC

            //配置Http请求管道
            public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
            {
                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                }
    
                app.UseRouting();
    
                app.UseEndpoints(endpoints =>
                {
                    /*                endpoints.MapGet("/", async context =>
                                    {
                                        await context.Response.WriteAsync("Hello World!");
                                    });*/
    
                    //endpoints.MapControllers();//使用路由特性,放置在 Cotroller/Action上时使用
                    endpoints.MapControllerRoute(
                        "default",
                        "{controller=Home}/{action=Index}/{id?}");
                });
            }
    

    其它常用中间件

            //配置Http请求管道
            public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
            {
                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                }
    
                app.UseStaticFiles(); //静态文件中间件,使得请求可以访问静态文件,比如图片,css,html
                //app.UseHttpsRedirection(); //将http请求转化为https请求
                //app.UseAuthentication(); //身份认证
                app.UseRouting(); //路由中间件
    
                app.UseEndpoints(endpoints =>
                {
                    /*                endpoints.MapGet("/", async context =>
                                    {
                                        await context.Response.WriteAsync("Hello World!");
                                    });*/
                    //endpoints.MapControllers();//使用路由特性,放置在 Cotroller/Action上时使用
                    endpoints.MapControllerRoute(
                        "default",
                        "{controller=Home}/{action=Index}/{id?}");
                    
                });
            }
        }
    
  • 相关阅读:
    CCCC练习即感
    1003 我能通过
    录制开讲啦杂感
    OOP第三次上机
    关于C++随机函数
    蓝桥杯杂感。
    CF502C The Phone Number
    It's a secret
    2017-06-22
    2017-05-12
  • 原文地址:https://www.cnblogs.com/easy5weikai/p/12992616.html
Copyright © 2011-2022 走看看