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?}");
                    
                });
            }
        }
    
  • 相关阅读:
    NodeJS、NPM安装配置步骤(windows版本)
    23种设计模式全解析
    js阻止浏览器默认事件
    js获取不同浏览器盒子宽度高度
    H5之重力感应篇
    JS中的call()和apply()方法
    html学习笔记
    less(css)语言快速入门
    power designer简单教程
    Strom开发配置手册
  • 原文地址:https://www.cnblogs.com/easy5weikai/p/12992616.html
Copyright © 2011-2022 走看看