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?}");
                    
                });
            }
        }
    
  • 相关阅读:
    vi/vim键盘图
    PostgreSQL学习----命令或问题小结
    PostgreSQL学习----模式schema
    OSM
    Spring基础(9) : 自动扫描
    Spring基础(8) : properties配置文件
    Spring基础(8) : 延迟加载,Bean的作用域,Bean生命周期
    Spring基础(7) : Bean的名字
    Spring基础(6) : 普通Bean对象中保存ApplicationContext
    Spring基础(5): 构造函数注入无法处理循环依赖
  • 原文地址:https://www.cnblogs.com/easy5weikai/p/12992616.html
Copyright © 2011-2022 走看看