【发布时间】:2017-07-16 15:51:01
【问题描述】:
我是一位经验丰富的 .NET 开发人员,在过去的几天里,我在 .NET Core 中迈出了第一步,更具体地说,是使用 ASP.net Core 构建 RESTful API。
我知道有 2 种可能的路由选项 - 约定路由(传统)与基于属性的路由(较新)。
我读到ASP.net core 的开发团队建议对 API 使用基于属性的路由,而不是传统的基于约定的路由,它更适合 MVC 应用程序。
我真的很想了解 - 为什么?
似乎基于属性的路由使我们编写了更多代码,最终具有与传统路由相同的行为。
【问题讨论】:
-
这篇推荐信写在哪里,可以分享一下吗?
-
这个问题主要是基于意见的。阅读文档docs.microsoft.com/en-us/aspnet/core/mvc/controllers/routing 并选择最适合您需求的文档。
-
@emrenevayeshirazi - 我一直在观看 Kevin Dockx 的 Pluralsight 课程,内容是使用 ASP.net 核心构建 RESTful 服务。该课程的作者说那里。
-
@Nkosi,我已经阅读了一些关于它的文章——包括你发送的那篇。但是仍然 - 如果构建框架的团队推荐了一些东西,我想这背后是有原因的,除非它只是为了语义
-
@DotnetProg 已授予。但即使他们推荐它,它仍然是一种意见。这是文档
This example highlights a key programming difference between attribute routing and conventional routing. Attribute routing requires more input to specify a route; the conventional default route handles routes more succinctly. However, attribute routing allows (and requires) precise control of which route templates apply to each action.中的注释之一
标签: c# asp.net asp.net-web-api asp.net-core .net-core