ASP.NET CORE, Web API: No route matches the supplied values

Benjamin Schäublin picture Benjamin Schäublin · Sep 12, 2016 · Viewed 25k times · Source

PLEASE NOTE: This question was asked in 2016. The original answer to this problem was to update the microsoft api versiong package. In the current days, the problem reoccurs, but for other reasons.

Original Question:


i have some problems with the routing in asp.net core (web api).

I have this Controller (simplified):

[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/[Controller]")]
public class DocumentController : Controller
{

[HttpGet("{guid}", Name = "GetDocument")]
public IActionResult GetByGuid(string guid)
{
    var doc = DocumentDataProvider.Find(guid);
    if (doc == null)
        return NotFound();

    return new ObjectResult(doc) {StatusCode = 200};
}


[HttpPost]
public IActionResult Create([FromBody] Document doc)
{
    //... Creating Doc

    // Does not work   
    var val = CreatedAtRoute("GetDocument", new {guid = doc.Guid.ToString("N")}, document);

    // or this: 
    CreatedAtRoute("GetDocument", new { controller = "Document", guid = doc.Guid.ToString("N")}, document);
    // neither this
    var val = CreatedAtRoute("GetDocument", new { version = "1", controller = "Document", guid = doc.Guid.ToString("N")}, document);

    return val;
}
}

If i call Create, the document is created and the routing object was created but i get the error "No route matches the supplied values" and get a 500 status.

I can call the GetByGuid directly, without any problems.

I couldn't find any debugging help for asp.net core (like any existing routing debugger).

I would appreciate any help!

EDIT Looks like it would be a bug from microsoft's versioning package.. if i define the fix route /api/v1/[Controller] it's working.

But that's not a solution for me.

Answer

Benjamin Schäublin picture Benjamin Schäublin · Sep 14, 2016

I'll answer my own question: It was really a bug in the versioning package of microsoft and it's gonna be fixed soon.

https://github.com/Microsoft/aspnet-api-versioning/issues/18