c# - 路由覆盖

标签 c# asp.net-core asp.net-core-routing

如果 Controller 中存在某些操作,我正在寻找一种方法来覆盖操作调用。

想象一下:

[Route("api/[controller]")]
public partial class UsersController : BaseController {
    [HttpGet("Friends/{id}")]
    public IActionResult GetFriends(int id) {
    // some code
    }

然后我在另一个文件中:

[Route("api/[controller]")]
    public partial class UsersController : BaseController {
        [HttpGet("Friends_custom/{id}")]
        public IActionResult GetFriends_custom(int id) {
        // some code
        }

我希望我的前端只调用

/users/friends

如果 _custom 存在,我如何获取 asp 路由以匹配它?

最佳答案

漫长的一天后,我发现我们可以使用 Order在路由属性中。它正是我需要的!

关于c# - 路由覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51733379/

相关文章:

c# - delegate 关键字与 lambda 表示法

c# - 如何获取网格新行的 RowHandle(当它生效时)(devexpress)

c# - 对象或值作为我的服务/数据层的参数

asp.net-core - NSwagStudio 液体模板

c# - 路由不适用于自托管 Web API

c# - MVC 6 多个获取方法

asp.net - ASP .NET Core : Routing. 开头的 url 中有多个类别

c# - Azure 服务总线 - 删除特定消息

asp.net - 由于 HttpPlatformHandler,Aurelia 无法在 azure 上加载?

reactjs - Material-ui-next typescript 错误