Dotnet Core Web API Versions
I created my first dotnet web site today and found what I cannot solve. I hope someone can figure out what I am doing wrong.
Here's the code that works as expected.
[Route("api/[controller]")]
public class HelpController : Controller
{
[HttpGet]
public string Get()
{
return "hello world";
}
}
However, when I try to apply version control, I get nothing.
[ApiVersion("1.0")]
[Route("api/{version:apiVersion}/[controller]")]
public class HelpController : Controller
{
[HttpGet]
public string Get()
{
return "hello world";
}
}
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
services.AddApiVersioning(option =>
{
option.ReportApiVersions = true;
option.DefaultApiVersion = new ApiVersion(1, 0);
option.AssumeDefaultVersionWhenUnspecified = true;
});
}
The code compiles as expected, but I am not getting anything. I think the url should be localhost://.../api/1/help
, but it doesn't work. It sends back 404. I've tried "1", "1.0", "1_0" and "10." Nothing works.
What am I missing?
+3
source to share