Effectively Setting Always ON for App Service on Microsoft Azure

Hosting providers unload your application after certain amount of time if the application is idle. Microsoft Azure provide Always ON option (with some extra cost) to keep the application always running. You can enable these settings from Azure Portal as show below:

However there is an issue if your application is running on HTTPS and you have rewrite rules to redirect HTTP traffic to HTTPS then Always ON settings in Azure will not work.

You can fix it in many ways, here is one of them. Add the following rewrite rule in your web.config, it should be first rule (if you have other rules in web.config):

        <rule name="Top Rules" enabled="true" stopProcessing="true">
          <!-- Please always keep this rule on the top of list -->
          <match url=".*" />
          <conditions logicalGrouping="MatchAny">
            <add input="{HTTP_USER_AGENT}" pattern="Initialization" ignoreCase="true"/>
            <add input="{HTTP_USER_AGENT}" pattern="AppInit" 		ignoreCase="true" />
            <add input="{HTTP_USER_AGENT}" pattern="WarmUp" 		ignoreCase="true"/>
            <add input="{HTTP_USER_AGENT}" pattern="AlwaysOn" 		ignoreCase="true"/>
          <action type="Rewrite" url="{URL}" />
Share it

2 thoughts on “Effectively Setting Always ON for App Service on Microsoft Azure

Comments are closed.