.net.net-coreasp.net-core-webapistartupasp.net-routing

.NET Core API redirect to 404 in startup configuration


I have quite tricky challenge to do, my app is going to have 3 different startup options. So 1 application that is differently hosted/has different use cases/routing. This is a design that we have to follow so cannot change that.

So now I need to have a switch, it can be based on appsetting that will turn off all controllers (map them to NotFound()) except for healthcheck. So we need to have this route working, but rest of them should map to NotFound like they were not existing. This is when value from appsettings will be set as to disable controller, and when it is enabled everything should work fine.

I saw some examples with routing set to non existing pages or something similar, some annotations on controller level, but we would like to do in startup and never think about it when new controller is created.


Solution

  • we used a feature called application parts, ConfigureApplicationPartManager()