Implement custom "System is restarting..." message in Sitefinity

August 16, 2014 Digital Experience

Until now, the message when the application pool is recycled was unextendable, but since our latest internal build (Sitefinity 7.1.5205), this could be easily achieved as our dev team exposed two methods in SitefinityHttpModule:

/// <summary>
        /// Called on begin request during system restarting. The request should be completed here, because the system will not be able to handle the request at this time.
        /// By default sends 'The system is restarting...' message and completes the request.
        /// Can be overridden to implement different behavior.
        /// </summary>
        /// <param name="context">The HTTP context.</param>
        protected virtual void OnSystemRestarting(HttpContext context);
 
        /// <summary>
        /// Sends a response message to the clients with the specified body html and delayed redirect. Completes the request.
        /// </summary>
        /// <param name="context">The HTTP context.</param>
        /// <param name="bodyHtml">The body HTML.</param>
        /// <param name="timeout">The timeout in milliseconds before redirect. By default it is 3000.</param>
        /// <param name="redirctUrl">The redirect URL. Optional, If it is not specified </param>
        public static void SendDelayedRedirect(HttpContext context, string bodyHtml, int timeout = 3000, string redirectUrl = null);

The steps necessary to change the message are as follows:

  1. Create custom SitefinityHttpModule:
  2. namespace SitefinityWebApp.Tests
    {
        /// <summary>
        /// Custom Sitefinity HTTP module - customize the default "The system is restarting..." message
        /// </summary>
        public class CustomSitefinityHttpModule : SitefinityHttpModule
        {
            /// <summary>
            /// Called on begin request during system restarting. The request should be completed here, because the system will not be able to handle the request at this time.
            /// By default sends 'The system is restarting...' message and completes the request.
            /// Can be overridden to implement different behavior.
            /// </summary>
            /// <param name="context">The HTTP context.</param>
            protected override void OnSystemRestarting(HttpContext context)
            {
                SitefinityHttpModule.SendDelayedRedirect(context, "<h2>Custom restarting message</h2><p>Please wait a few seconds. You will be redirected automatically.</p>");
            }
        }
    }

  3. Register the module in the web.config replacing the default one:
  4. <system.webServer>
        <modules runAllManagedModulesForAllRequests="true">
          <add name="Sitefinity" type="SitefinityWebApp.Tests.CustomSitefinityHttpModule, SitefinityWebApp" />
          ...

After recycling the application pool the change should take effect.

Vassil Vassilev