博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
30-RoutingMiddleware介绍以及MVC引入
阅读量:4325 次
发布时间:2019-06-06

本文共 1496 字,大约阅读时间需要 4 分钟。

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
() ); app.UseRouter(router); //第二种方式 app.Map("/task",taskApp=>{ //路由匹配 taskApp.Run(async (context)=>{ await context.Response.WriteAsync("i am task"); }); }); } }

 

转载于:https://www.cnblogs.com/qinzb/p/9346282.html

你可能感兴趣的文章
洛谷 CF937A Olympiad
查看>>
Codeforces Round #445 C. Petya and Catacombs【思维/题意】
查看>>
用MATLAB同时作多幅图
查看>>
python中map的排序以及取出map中取最大最小值
查看>>
ROR 第一章 从零到部署--第一个程序
查看>>
<form>标签
查看>>
vue去掉地址栏# 方法
查看>>
Lambda03 方法引用、类型判断、变量引用
查看>>
was集群下基于接口分布式架构和开发经验谈
查看>>
MySQL学习——MySQL数据库概述与基础
查看>>
ES索引模板
查看>>
HDU2112 HDU Today 最短路+字符串哈希
查看>>
JPanel重绘
查看>>
图片放大器——wpf
查看>>
SCALA STEP BY STEP
查看>>
cocos2d-x学习笔记
查看>>
MySql中的变量定义
查看>>
Ruby数组的操作
查看>>
hdu1181暴搜
查看>>
解码字符串 Decode String
查看>>