Using various ways in order to conditionally disable endpoints
In this demo, i m using various ways in order to disable some endpoints in production environment.
1️⃣ Using feature provider
ConditionalControllerProvider
to enable/disable endpoints based on environment.2️⃣ Using action filter
ConditionalActionFilterAttribute
to enable/disable endpoints based on environment.3️⃣ Using middleware
ConditionalMiddleware
to enable/disable endpoints based on environment.4️⃣ Using feature flags
ConditionalFeatureFilter
to enable/disable endpoints based on environment.
The first way is the simplest one in my opinion. The other ways needs more code to disable endpoints also in swagger.
In order to simulate the behaviour in production environment :
➖ Open file
launchSettings.json
of some project for example01-Way
➖ Edit the appropriate profile for example
_01_Way
orIIS Express
➖ Set variable
ASPNETCORE_ENVIRONMENT
toProduction
value
Tools
: vs22, net 6.0