3

Background

We are trying to make use of azure deployment slots when we deploy our Sitecore 9.1 PaaS solution to Azure. However, it seems that after a slot swap, the site is not warmed up, which affects the first user of the website (=slow startup time).

Our entire website, is behind login (requireLogin=true), but we have some endpoints that are publicly available.

What we tried

Following the suggestions from several blogs, we tried the following:

  • configure IIS application initialization, e.g:
<applicationInitialization doAppInitAfterRestart="true" xdt:Transform="Insert">
      <add initializationPage="/" hostName="[URL-here]"/>
      <add initializationPage="/api/content/getloginconfig" hostName="[URL-here]"/>
      <add initializationPage="/init/warmup" hostName="[URL-here]"/>
      <add initializationPage="/auth/errors/accessdenied" hostName="[URL-here]"/>
      <add initializationPage="/auth/forgotpassword" hostName="[URL-here]"/>
    </applicationInitialization>
  • verified that we do not have any deployment slot specific settings

  • added rewrite rules to handle https redirection:

<rule name="Root Hit Force HTTPS Redirection" enabled="true" stopProcessing="true"
              xdt:Transform="Replace" xdt:Locator="Match(name)">
          <match url="^$" ignoreCase="false"/>
          <conditions>
            <add input="{WARMUP_REQUEST}" pattern="1" negate="true" />
            <add input="{REMOTE_ADDR}" pattern="^100?\." negate="true" />
            <add input="{HTTPS}" pattern="^OFF$"/>
            <add input="{HTTP_METHOD}" pattern="GET"/>
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}/" redirectType="Permanent"/>
        </rule>
        <rule name="Sitecore Login or Admin Force HTTPS Redirection" enabled="true" stopProcessing="true"
              xdt:Transform="Replace" xdt:Locator="Match(name)">
          <match url="^(sitecore/(login|admin))$"/>
          <conditions>
            <add input="{WARMUP_REQUEST}" pattern="1" negate="true" />
            <add input="{REMOTE_ADDR}" pattern="^100?\." negate="true" />
            <add input="{HTTPS}" pattern="^OFF$"/>
            <add input="{HTTP_METHOD}" pattern="GET"/>
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent"/>
        </rule>
        <rule name="Forbidden" xdt:Transform="Remove" xdt:Locator="Match(name)" />
        <rule name="Force HTTPS Redirection" enabled="true" stopProcessing="true"
              xdt:Transform="Insert">
          <match url="(.*)" ignoreCase="false"/>
          <conditions>
            <add input="{WARMUP_REQUEST}" pattern="1" negate="true" />
            <add input="{REMOTE_ADDR}" pattern="^100?\." negate="true" />
            <add input="{HTTPS}" pattern="^OFF$"/>
            <add input="{HTTP_METHOD}" pattern="GET"/>
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
        </rule>

What are the best practices when using deployment slots for a website entirely behind login (requireLogin=true)?

4

Application Initialization does a call to your website over http. If you have redirect rules that redirect http to https, the initialization receives a 302 and marks the request as done, it does not follow the 302 to load the site on https.

So in order to avoid this, you need to add an additional rules in your rewrite rules to skip the https redirect in case of application initialization. These requests can be identified by the "Initialization" user agent.

In essence, you wan to add this rule on the top of your rewriterules:

<rule name="No redirect on warmup request" stopProcessing="true">
  <match url=".*" />
  <conditions>
    <add input="{HTTP_USER_AGENT}" pattern="Initialization" />
  </conditions>
  <action type="Rewrite" url="{URL}" />
</rule>
  • Couldn't this be handled by <add initializationPage="/auth/forgotpassword" hostName="https://[URL-here]"/>? – Mark Cassidy Jul 3 at 11:07
  • 1
    No, it doesn't work like that, you cannot specify a scheme in applicationInitialization. The hostname is without schema. – Bart Verdonck Jul 3 at 11:09
  • Detailed info can be found in my blog article: onelittlespark.bartverdonck.be/… and my sources: zankavtaskin.com/2016/12/… – Bart Verdonck Jul 3 at 11:13
  • I should have added to the question, that we already use redirect rules. They have now been added and have been copied almost 1:1 from ruslany.net/2017/11/…. However, they look a bit different than the one you posted, so I will give your suggestion a try. Thanks! – Hos Jul 3 at 12:26
  • If I set requireLogin to false and add your rewrite rule as the first rule, it seems to work. However, when I set requireLogin to true, it is suddenly slow again. I guess I need to update the logic in my /init/warmup endpoint to do some more heavy Sitecore queries to also make it work with requireLogin enabled? – Hos Jul 4 at 11:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.