I have two AppServices, TestAppService and Test2AppService. I want calls to Test to be redirected to Test2, for example:
http://localhost:21021/api/services/app/Test/GetAll
should give me the results of
http://localhost:21021/api/services/app/Test2/GetAll
But I cannot edit TestAppService.
For now my workaround is renaming the controller during Module initialization:
.ConfigureControllerModel(model =>
{
if (model.ControllerName == "Test")
model.ControllerName = "Test2";
// Need to rename Test2 or it would be ambiguous
else if (model.ControllerName == "Test2")
model.ControllerName = "Test";
});
Is there a better/simpler way to do this? I actually only need to redirect one method.
Assuming that you are using AspNetCore.
You could disable TestAppService with [RemoteService(false)]
, see https://aspnetboilerplate.com/Pages/Documents/AspNet-Core#application-services-as-controllers
Follow by adding route attribute like [Route("api/test/[action]")]
to your Test2AppService
Was able to do it using a HttpGet attribute with Order = -1:
[HttpGet("api/services/app/Test/GetAll", Order = -1)]
public async override Task<List<Data>> GetAll()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.