zoukankan      html  css  js  c++  java
  • 30-RoutingMiddleware介绍以及MVC引入

    1-构建路由

     public class Startup
        {
            // This method gets called by the runtime. Use this method to add services to the container.
            // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
            public void ConfigureServices(IServiceCollection services)
            {
                services.AddRouting(); //如果采用第一种方式,必要加上些条命令
            }
    
            // 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();
                }
    
               //第一种方式
                app.UseRouter(myhandler=>{
                    myhandler.MapGet("action",context=>context.Response.WriteAsync("this is action") );
                });
    
              //第一种方式,自己构建route
                RequestDelegate handler = context =>  context.Response.WriteAsync("i am router"); 
                var router = new Route(
                    new RouteHandler(handler),
                    "myaction",
                    app.ApplicationServices.GetRequiredService<IInlineConstraintResolver>()     
                );
                app.UseRouter(router);
    
                //第二种方式
                app.Map("/task",taskApp=>{ //路由匹配
                    taskApp.Run(async (context)=>{
                        await context.Response.WriteAsync("i am task");
                    });
                });
    
            }
        }
  • 相关阅读:
    Linux下mysql的自动定时备份
    javaweb面试题
    java面试题
    Web应用优化之nginx+tomcat集群配置+redis管理session
    Web应用系统通常可以经过哪些层面的优化
    HBase安装
    博客园所有文章字数统计
    Python生成器
    Python列表生成式
    直方图均衡化-Python实现
  • 原文地址:https://www.cnblogs.com/qinzb/p/9346282.html
Copyright © 2011-2022 走看看