简体   繁体   中英

App_Offline.htm redirect using UrlRewriting

We host a multi-tenant web site which is branded to suit the client based on the domain name. The web site is developed using Asp.net MVC4.

We plan to use the app_offline.htm file to take the web site offline during maintenance periods. However, we want the maintenance page to be branded based on the domain. In order to achieve this, we decided to use the UrlRewrite module.

The logic for the rewrite rule is that if the request is from a specific domain and the app_offline.htm file exists in the web site, then redirect to that domain specific (branded) app_offline page. The rules in our web.config are as below:

   <!-- App_Offline redirects -->
  <rewrite>
  <rules>
    <rule name="Domain1 App_offline redirects" stopProcessing="true">
      <match url="^(.)*" />
      <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_HOST}" pattern="^domain1" />
        <add input="{DOCUMENT_ROOT}/app_offline.htm" matchType="IsFile" />
        <add input="{REQUEST_URI}" pattern="domain1.app_offline.htm" negate="true" />
      </conditions>
      <action type="Redirect" url="https://{SERVER_NAME}/domain1.app_offline.htm" />
    </rule>
    <rule name="Domain2 App_offline redirects" stopProcessing="true">
      <match url="^(.)*" />
      <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_HOST}" pattern="^domain2" />
        <add input="{DOCUMENT_ROOT}/app_offline.htm" matchType="IsFile" />
        <add input="{REQUEST_URI}" pattern="domain2.app_offline.htm" negate="true" />
      </conditions>
      <action type="Redirect" url="https://{SERVER_NAME}/domain2.app_offline.htm" />
    </rule>
  </rules>
</rewrite>

The problem we now face is that though this Url rewrite rule kicks in and redirects the user to the branded offline page, it initially displays the content of the non-branded app_offline.htm page. After a couple of seconds, on refreshing the page, the actual branded content is displayed.

We also noticed that when the generic app_offline.htm content is displayed, the HTTP response is a 503, whereas when the branded app_offline.htm is displayed later, the HTTP status is 200.

Is there any way that we can overcome the initial display of the generic app_offline.htm content?

Do you see any performance issues with the above Url rewrite approach?

Thanks in advance.

EDIT: I have realised that the refreshing the domain specific app_offline page causes it to be cached in the browser and thats where the content is displayed from. Without refreshing the branded app_offline page, trying to access any other page on the site always displays the generic app_offline.htm content :) So, looking at alternatives....

Found a solution to this problem.

  1. Created a new folder called 'Offline'
  2. Moved the domain specific app_offline.htm pages to this offline folder.
  3. Set up the 'Offline' folder as an application in IIS.

Works perfectly, both in IIS Express and IIS

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM