应用程序之间的差异.地图和应用程序.使用端点+端点.地图



看起来以下两个正在工作:

app.UseRouting();
// http://localhost/apple
app.UseEndpoints(endpoints =>
{
endpoints.Map("/apple", async context =>
{
await context.Response.WriteAsync("this is an apple");
});
});
// http://localhost/orange
app.Map("/orange", orangeApp =>
{
orangeApp.Run(async context =>
{
await context.Response.WriteAsync("this is an orange");
});
});

这两种映射方式有什么区别?

app.Map不使用路由,它是一个从简单的字符串比较开始的。中间件的顺序很重要,没有组合模型(映射按顺序运行(,也不支持参数或更复杂的过滤逻辑。

另一个Map(端点路由(是路由系统,因此它与注册的其他路由组成。这支持参数、排序、约束和其他可扩展性。在此处阅读有关路由的更多信息https://learn.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-5.0

相关内容

最新更新