I need to disable a route temporarily in an asp.net webapi app and I cannot do compile and do another deploy.
Can I just a disable a asp.net web api route in web.config?
I don't think you can disable a specific route in web.config. Normally if you want to disable a route, you can use IgnoreRoute
, or just remove the route in WebApiConfig.cs
or Global.asax
file wherever the route exists.
Since you only want to do it in web.config without doing compile and another deploy, I can only think about two ways.
1) Use URL Rewriting
<rewrite>
<rules>
<clear />
<rule name="diableRoute" stopProcessing="true">
<match url="api/YourWebApiController" />
<action type="Redirect" url="Error/NotFound" appendQueryString="false" />
</rule>
</rules>
</rewrite>
This result will return the 404 Error page.
2) Setting authorization rules
<location path="api/YourWebApiController">
<system.web>
<authorization>
<deny users="*"/>
</authorization>
</system.web>
</location>
This result will return to the login page, because the access to the web api route is denied.
You can customize either one to your need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With