[英]Difference between app.Map and app.UseEndpoints + endpoints.Map?
Looks like following two are working:看起来以下两个正在工作:
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");
});
});
What's the difference between these two ways of mapping?这两种映射方式有什么区别?
app.Map
doesn't use routing, it's a starts with simple string comparison. app.Map
不使用路由,它是从简单的字符串比较开始的。 The order of the middleware is important, there's no composition model (maps run in order) and there's no support for parameters or more complex filtering logic.中间件的顺序很重要,没有组合模型(地图按顺序运行)并且不支持参数或更复杂的过滤逻辑。
The other Map (endpoint routing) is the routing system so it composes with other routes registered.另一个 Map(端点路由)是路由系统,因此它与其他注册的路由组成。 This supports parameters, ordering, constraints and other extensibility.这支持参数、排序、约束和其他可扩展性。 Read more about routing here https://docs.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-5.0在此处阅读有关路由的更多信息https://docs.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-5.0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.