Having 2 route attributes at the controller level works fine in a new RC1 application:
[Produces("application/json")]
[Route("api/[controller]")]
[Route("api/old-log")]
public class LogController: Controller
{
[HttpGet]
public IActionResult GetAll()
{
return Json(new { Foo = "bar" });
}
}
Both http://localhost:62058/api/log
and http://localhost:62058/api/old-log
return the expected json. The only caveat I have seen is that you might want to set the name/order properties of the attributes in case you need to generate the url to one of those actions.
Having 2 Attributes on the action also works:
[Produces("application/json")]
public class LogController : Controller
{
[Route("api/old-log")]
[Route("api/[controller]")]
[HttpGet]
public IActionResult GetAll()
{
return Json(new { Foo = "bar" });
}
}
However you need to be careful when having a general route at the controller level and a specific action route. In these cases the route at the controller level is used as a prefix and prepended to the url (There is a nice article about this behavior here). This might get you a different set of urls than you were expecting, for example with:
[Produces("application/json")]
[Route("api/[controller]")]
public class LogController : Controller
{
[Route("api/old-log")]
[Route("")]
[HttpGet]
public IActionResult GetAll()
{
return Json(new { Foo = "bar" });
}
}
The 2 routes that your application will listen in the last case will be http://localhost:62058/api/log
and http://localhost:62058/api/log/api/old-log
since api/log
is added as prefix to all the routes defined at the action level.
Finally, another option would be to use attributes for your new routes and then use the route table in the startup class to provide specific routes that take care of the old api.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…