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?}");
                    
                });
            }
        }
    
  • 相关阅读:
    autocomplete="off" 不起作用
    IE8兼容模式设置
    H5学习
    wampserver安装配置
    HTML5音乐播放器(最新升级改造加强版)
    HTML5+CSS3+jquery实现简单的音乐播放器
    jquery+css3实现3d滚动旋转
    HTML5游戏设计与开发 小白7-9月的动态
    jquery submit()不执行
    html5手机常见问题与工具分享
  • 原文地址:https://www.cnblogs.com/easy5weikai/p/12992616.html
Copyright © 2011-2022 走看看