Sitefinity's application status page can cause you big problems

by Vesselin Vassilev


Last Updated On Jul 14, 2017


You've probably seen it - when the site starts for the first time or has just been restarted there is a nice, friendly-looking status page, showing a message that the system is restarting (8.1) or system is initializing (8.2+).

But, here is the catch - no matter what resource you request during system restart, Sitefinity replies with HTTP Status Code 302 Found (moved temporarily) providing the URL of the status page to the Location header:

response_code_302

You see - you request bundle.min.js and it responds with 302 Found and moved temporarily to /sitefinity/status?... which returns HTTP status 200 OK and the HTML of the status page.

Now imagine this request was made by your CDN like Akamai - it will request the bundle.min.js see the 302 response and then go to the status page. It will then cache the response of the status page (which is HTML and not javascript, remember).

Next, all requests from users to the bundle.min.js will return html instead of real javascript. As a result your site will probably be broken.

And this can happen not only to javascript files - any resource is prone to this error. 

Below is a real example of a cached image request - it returns the bloody html of the system is restarting message. This is a live high traffic site, using Akamai as CDN:

image_system_restarting

What's the solution: get rid of the friendly status page and simply return HTTP status code 503 to let all intermediate devices (CDN, Load Balancers, etc.) that there is a problem with this resource and they should try later.

That's really easy and is described well in the Sitefinity's documentation. I wish they had an easier way to disable this functionality.

UPDATE 14-Jul-2017: As of Sitefinity 9, you can configure the Status page's HTTP response code via a web.config change - just add this line in the <appSettings> section:
<add key="sf:AppStatusPageResponseCode" value="503" />

Source: http://docs.sitefinity.com/change-the-application-status-page-response-code

Use the solution below only if your version of Sitefinity is older than v.9.

Derive from the SitefinityHttpModule and override the OnSystemRestarting method:

public class CustomHttpModule : SitefinityHttpModule
{
        protected override void OnSystemRestarting(HttpContext context)
        {
            context.Response.StatusCode = 503;
        }
}


EDIT: Thanks to Denis who pointed out that the signature of the OnSystemRestarting event has changed in version 8.2 and above. It looks like this:

protected virtual void OnSystemRestarting(HttpContext context, string html = null, string scriptUrl = null)
{
   context.Response.StatusCode = 503;
}


Really simple, then register your module in the web.config by replacing the SitefinityHttpModule with your custom one:

<add name="Sitefinity" type="SitefinityWebApp.CustomHttpModule, SitefinityWebApp" />



Copyright © Sitefinity Development