404 response code caused by App Services – AlwaysOn feature

Developer Support

In this post, Sr. Consultant Adel Ghabboun shows how to optimize Azure App Service against cold starts using AlwaysOn.


Use case:

  • Azure App service with AlwaysOn feature = True (See below screenshot)
  • Traffic Manager and Application Gateway are used, which relay on health probes to determine the availability and health of the App Service
  • Application Insights for monitoring

Symptoms:

  • App Service Always On also generate periodic (every 5min) probes to app instances and causing failed requests with error 404, and this can be found in Application Insights as below

Solution:

This can be fixed by rewriting the Always on path. After a cold start of your application, AlwaysOn will send a request to the ROOT of your application “/”.  Whatever file is delivered when a request is made to / is the one which will be warmed up, which will fail because the root doesn’t exist.

If you wanted AlwaysOn to warmup a specific page instead of the root, then you can implement this URL Rewrite rule.

<?xml version="1.0" encoding="UTF-8" standalone="no">
<configuration>
    <system.webServer>
      <rewrite>
        <rules>
          <rule name="Rewrite AlwaysOn" stopProcessing="true">
            <match url="^$" />
            <conditions>
              <add input="{HTTP_USER_AGENT}" pattern="^AlwaysOn$" />
            </conditions>
            <action type="Rewrite" url="/api/Online/Ping" />
          </rule>
        </rules>
      </rewrite>
    </system.webServer>
</configuration>

 

 

Please refer here for more details.

Something to note here that if you are already using Azure Traffic Manager service with a health probe periodically pinging the site/path, AlwaysOn would be redundant as the web app will be kept warm by the health probes.

 

2 comments

Discussion is closed. Login to edit/delete existing comments.

  • Colton Williams 0

    Thank you for this! I could not figure out where all of the failed requests were coming from (I had validated our health probes and availability checks). I did not understand how AlwaysOn actually worked, thanks again!

  • Smith, Jacob 0

    How does one handle this when they are using linux-based App Services?

Feedback usabilla icon