0
votes

I have an ASP.NET MVC application running as an Azure App Service. There's a deprecated API included on mydomain.com/api/* that I want to close down because I now have api.mydomain.com/*. Once the deprecated API is shut down, some people may still be making requests to it. I can create a simple controller that returns 404 or something like that. But I would like to hear if someone knows a solution in Azure where I can "blacklist" URLs like /api/* or similar before even hitting my application. I know that there are different products available on Azure where I can include handlers before my website, like API Management. But I would prefer not to change too much, why a feature directly on the app service, a rewrite rule, or similar would be awesome here. I simply don't want the performance overhead of invoking my own application when a request for a URL that I know shouldn't do anything comes in.

1

1 Answers

0
votes

You can achieve that using URL Rewrite. Rather than blocking the old path, you just redirect to the new one. Add the following block to a web.config file

<configuration>
  <system.webServer>  
    <rewrite>  
        <rules>  
          <rule name="Redirect rquests to default azure websites domain" stopProcessing="true">
            <match url="(.*)" />  
            <conditions logicalGrouping="MatchAny">
              <add input="{HTTP_HOST}" pattern="^mydomain\.com\/api/(.*)" />
            </conditions>
            <action type="Redirect" url="https://api.mydomain.com/{R:0}" />  
          </rule>  
        </rules>  
    </rewrite>  
  </system.webServer>  
</configuration>

Source: https://stackoverflow.com/a/36631234/1384539