I am trying to design a API versioning, but I am getting following error
Multiple actions matched. The following actions matched route data and had all constraints satisfied
I didn't want to duplicate all controller methods instead I just override whatever changed but unchanged causes the error. is that bad practice what I am trying? any solution to my problem?
[ApiVersion( "1.0" )]
[AllowAnonymous]
[Route("api/v{api-version:apiVersion}/[controller]")]
public class HeartbeatController : Controller
{
[AllowAnonymous]
[HttpGet, MapToApiVersion("1.0")]
public virtual IActionResult Beat()
{
return Ok(DateTime.Now.ToString("HH:mm:ss"));
}
[AllowAnonymous]
[HttpGet, MapToApiVersion("0.9")]
public virtual IActionResult Get()
{
return Ok(Environment.MachineName);
}
}
[ApiVersion("2.0")]
[AllowAnonymous]
[Route("api/v{api-version:apiVersion}/[controller]")]
public class HeartbeatController : V1.Controllers.HeartbeatController
{
[AllowAnonymous]
[HttpGet]
public override IActionResult Get()
{
return Ok("this is version 2 " + Environment.MachineName);
}
}