简体   繁体   English

app.Map 和 app.UseEndpoints + endpoints.Map 的区别?

[英]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.

相关问题 app.UseRouting() 和 app.UseEndPoints() 有什么区别? - What are the differences between app.UseRouting() and app.UseEndPoints()? 在 ASP.NET Core 中使用 app.Run 和 app.UseEndpoints 有什么区别? - What are the difference using app.Run and app.UseEndpoints in ASP.NET Core? 为什么在多次调用 app.UseEndpoints(..) 时不执行中间件? - Why is middleware not executed when there are multiple calls to app.UseEndpoints(..)? OWIN app.use vs app.run vs app.map - OWIN app.use vs app.run vs app.map 如何在 app.UseEndPoints 中将自定义路由操作作为委托实例添加到 ASP.NET Core 3.1 应用程序? - How to add custom routed action as a delegate instance to ASP.NET Core 3.1 app in app.UseEndPoints? ASP.NET CORE 没有 app.UseEndpoints() 方法 - ASP.NET CORE Don't have app.UseEndpoints() Method asp.net core:有没有办法在管道中使用 app.Map() 将请求分支到根路径? - asp.net core: is there a way to branch a request to the root path using app.Map() in the pipeline? ASP> NET Core 2.1:app.Map中的新类实例 - ASP>NET Core 2.1 : New class instance inside app.Map 在通用应用程序中绑定到地图 - Binding to a Map in a universal app 缓存对象和哈希映射之间的区别 - Difference between Caching object and Hash map
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM