I am in the need to use routes to API controller methods as prefixes for redirects.
I (of course) could hardcode them but I would prefer to get them dynamically so if I change the routing or controller names it gets updated by the logic.
[Route("api/v1/[controller]")]
public class TestController : ControllerBase
{
[HttpGet("{path}")]
public async Task<IActionResult> Get(string path)
{
string prefix = "api/v1/Other/"; //how to get that part dynamically?
return Redirect(prefix + path);
}
}
[Route("api/v1/[controller]")]
public class OtherController : ControllerBase
{
[HttpGet("{path}")]
public async Task<IActionResult> Get(string path)
{
}
}
How would I get the prefix in TestController as string dynamically updating if the Route annotation or the controller name changes? I really need it at string.