Skip to content
This repository was archived by the owner on Nov 27, 2018. It is now read-only.
This repository was archived by the owner on Nov 27, 2018. It is now read-only.

Use a tilde (~) on the method attribute to override the route prefix does not work if not followed by a slash (/) #320

@NinoFloris

Description

@NinoFloris

As can be read here:
http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2
The proper way to break out of the route prefix set at controller level for instance is to prepend the route with a tilde.

However not following this tilde with a slash does not work and the request ends up in another action.

This works (simplified):

[Route("api/v1/[controller]")]
public class CommentsController {
    [HttpGet("~/api/v1/pages/{id:int}/[controller]")]
    public Task<IEnumerable<Model>> GetMany(...) { ... }
}

[Route("api/v1/[controller]")]
public class PagesController {
    [HttpGet("{ptSlug}/{slug}")]
    public Task<Model> GetByPath(...) { ... }
}

(Take note of the subresource literal route GetMany which overlaps with GetByPath)
A call to /api/v1/pages/123/comments correctly ends up in GetMany
However changing the GetMany route to:

[HttpGet("~api/v1/pages/{id:int}/[controller]")]

Kills the joy and the request will now end up in GetByPath.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions