May 24th, 2019

404 response code caused by App Services – AlwaysOn feature

Developer Support
Cloud Solution Architects

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.

 

Author

Developer Support
Cloud Solution Architects

Microsoft Developer Support helps software developers rapidly build and deploy quality applications for Microsoft platforms.

2 comments

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

Newest
Newest
Popular
Oldest
  • Smith, Jacob

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

  • Colton Williams

    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!

Feedback