Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I disable a asp.net web api route in web.config?

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?

like image 840
yang-qu Avatar asked Feb 14 '14 02:02

yang-qu


1 Answers

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.

like image 164
Lin Avatar answered Sep 21 '22 03:09

Lin