I'm using ASP.NET Core 6 and trying to have the base path of my API controller be configurable (so that users can choose the base path themselves to avoid conflicts with other controllers).
I tried setting up the following route:
string configurablePrefix = "/temp";
endpoint.MapControllerRoute(
name: "MyRouteName",
pattern: configurablePrefix + "/{action=MyDefaultAction},
defaults: new { controller = "MyController" });
Where MyController
is defined like this:
[ApiController]
public class MyController : ControllerBase
{
[HttpGet("MyDefaultAction")]
public IActionResult MyDefaultAction()
{
return new JsonResult("Hello");
}
}
This causes no errors during startup, but when I access `https://localhost/temp/MyDefaultAction I get a 404
How can I get this to work so that actions in MyController
are accessible on whatever start path the user chooses (i.e. change it to respond to /othertemp/MyDefaultAction
instead)?