Подход 1:
[Route("test/{*any}")]
[ApiController]
public class TestController : Controller
{
// so that all request that start with 'test' go through this method
public IActionResult Process()
{
return new JsonResult(new{
a = 1,
});
}
}
Подход 2:
зарегистрировать маршрут общего доступа:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapRoute(
name:"routeAny",
template:"test/{*any}",
defaults: new{
Controller = "Test",
Action = "Process",
}
);
});
И удалите атрибут [ApiController]
, так как для него требуется [Route()]
:
<strike>[ApiController]</strike>
public class TestController : Controller
{
// so that all request that start with 'test' go through this method
public IActionResult Process()
{
return new JsonResult(new{
a = 1,
});
}
}