Web API 5.0.0-rc1 breaking default routes

347 Views Asked by At

Before I updated from Web API 5.0.0-beta2 to 5.0.0-rc1 I could do something like this:

[RoutePrefix("api/v1/test")]
public class TestController : ApiController
{
    [HttpGet]
    public TestString Get()
    {
        return new TestString { str = "HELLO WORLD" };
    }
}

so when I went to the URL /api/v1/test it would land on the Get() function.

After updating to Web API 5.0.0-rc1 I get a 404 when going to /api/v1/test

However, this works:

[RoutePrefix("api/v1")]
public class TestController : ApiController
{
    [HttpGet("test")]
    public TestString Get()
    {
        return new TestString { str = "HELLO WORLD" };
    }
}

Can you explain why this doesn't work any longer?

** EDIT ** [HttpGet("")] works. Then it breaks on that Get() function.

1

There are 1 best solutions below

1
On

I am not sure but I believe the Http[Get, Post, etc] type attributes have had their routing properties removed. This link hints at it:

http://blogs.microsoft.co.il/blogs/bnaya/archive/2013/08/28/asp-net-web-api-attribute-based-routing.aspx

be aware that most of the Attribute based Routing samples available today on the web, is using old attribute like [PUT] or [HttpPut] which is no longer supported on the latest bit (currently available from the ASP.NET nightly build, http://www.myget.org/F/aspnetwebstacknightly/ ), those attributes ware replaced with [Route] attribute.

Please see https://aspnetwebstack.codeplex.com/SourceControl/list/changesets and https://aspnetwebstack.codeplex.com/workitem/1206. Basically, the goal is to separate verb filters from attribute routing.