【ASP.NET Core快速入门】(九) RoutingMiddleware介绍以及MVC引入
生活随笔
收集整理的這篇文章主要介紹了
【ASP.NET Core快速入门】(九) RoutingMiddleware介绍以及MVC引入
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
前言
前面我們介紹了使用app.Map來配置路由,但是對于一般不是特別大的項目來說,我們不使用Map來進行路由配置。
配置路由
我們首先需要在Startup.cs文件中的ConfigureServices方法中進行路由依賴注入
services.AddRouting();接下來我們就可以在Configure中使用擴展方法進行注冊路由
//第一種方式app.UseRouter(builder=>builder.MapGet("actionfirst",async context =>{await context.Response.WriteAsync("this is first action");}));//第二種方式RequestDelegate handler=context=>context.Response.WriteAsync("this is second action");var route=new Route(new RouteHandler(handler),"actionsecond",app.ApplicationServices.GetRequiredService<IInlineConstraintResolver>());app.UseRouter(route);//第三種方式:不常用app.Map("/task",taskApp=>{taskApp.Run(async context=>{await context.Response.WriteAsync("this is a task");});});?
轉載于:https://www.cnblogs.com/wyt007/p/8125574.html
總結
以上是生活随笔為你收集整理的【ASP.NET Core快速入门】(九) RoutingMiddleware介绍以及MVC引入的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python-面向对象
- 下一篇: asp.net ajax控件工具集 Au