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");
                    });
                });
    
            }
        }
  • 相关阅读:
    C语言博客作业03--函数
    c语言博客作业02--循环结构
    C语言博客作业02--循环结构
    C博客作业01--分支、顺序结构
    c语言博客作业02--循环结构
    C博客作业02--循环结构
    c博客作业02--循环结构
    C语言博客作业03--函数
    C语言博客作业02--循环结构
    C博客作业03--函数
  • 原文地址:https://www.cnblogs.com/qinzb/p/9346282.html
Copyright © 2011-2022 走看看