7
votes

Azure App Service AlwaysOn works perfectly once there is no custom domain set for the web application. Once custom domain is added along with URL rewrite rule to redirect all incoming request to it, application starts to response slowly after some time of inactivity. Logs show that AlwaysOn still pings azure domain and gets HTTP 301 response ans is not trying to request new URL.

Log without custom domain:

2017-06-20 17:17:02 ZZTESTSITE GET / X-ARR-LOG-ID=743965b6-d3e2-42b9-9353-7772f9fbc898 80 - ::1 AlwaysOn ARRAffinity=b5289afa9cd711b67c1fe9137a6e3ff232f80bd3fa1bd96e9fc89992472b4e57 - zztestsite.azurewebsites.net 200 0 0 11433 652 15

Log with custom domain

2017-06-21 13:28:52 ZZTESTSITE GET / X-ARR-LOG-ID=ffcd5992-5019-48ca-a386-76443a8c7226 80 - ::1 AlwaysOn ARRAffinity=b5289afa9cd711b67c1fe9137a6e3ff232f80bd3fa1bd96e9fc89992472b4e57 - zztestsite.azurewebsites.net 301 0 0 553 652 46

URL Rewrite rule:

<rule name="Redirect requests from default azure websites domain to custom one" stopProcessing="true">
  <match url="(.*)" />
  <conditions logicalGrouping="MatchAny">
    <add input="{HTTP_HOST}" pattern="^zztestsite\.azurewebsites\.net$" />
  </conditions>
  <action type="Redirect" url="http://mycustomdomain.com" redirectType="Permanent" appendQueryString="false"/>
</rule>

Additionally once SSL in enabled and another rule is added to redirect all requests to HTTPS, same issue will arise.

How can I tackle this problem? I found two possible directions:

  1. Push AlwaysOn to ping custom domain (possibly https as an option)
  2. Change URL Rewrite rule to one allowing AlwaysOn to ping azure domain, but all other shall be redirected

Please advise.

2

2 Answers

5
votes

Try adding this line to your conditions:

<conditions>
  <add input="{HTTP_HOST}" pattern="^zztestsite\.azurewebsites\.net$" />
  <add input="{WARMUP_REQUEST}" pattern="1" negate="true" />
</conditions>

This tells is not to redirect for the Always On pings. Also note that I removed the MatchAny, as you really want MatchAll here (irrelevant when you only had one).

See here for a more complete example. It's for redirecting http to https, but the core idea is the same with respect to Always On requests. That example is an xdt transform, so it looks a bit different from 'straight' config. In fact you might consider using such xdt instead of polluting your web.config.

4
votes

Finally I found the rule which works

<rule name="AlwaysOn agent requests without any redirections" stopProcessing="true">
  <match url="^$"/>
  <conditions>
    <add input="{HTTP_USER_AGENT}" pattern="^AlwaysOn$" />
  </conditions>
  <action type="None" />
</rule>

I put it as a first rule. Then other rules follow like "azure domain to custom domain redirect" and "HTTP to HTTPS". David's answer was helpful however solves a bit different issue.