In case anyone is looking for a similar solution, here's where we ended up:
The requirement was to have any application user redirected to a maintenance page without running any data queries (since the point of maintenance mode is that the APIs will be down).
We tried setting a site property in the shared module where the layout lives, checking that property in the OnInitialize of the layout, throwing an exception if we're in maintenance mode, and redirecting to the maintenance page in the exception handler. This did not work, because the layout OnInit fires after the page OnInit (allowing page content to render and data queries to fire). Additionally, if the layout throws the exception is it not handled in the layout module, it is caught by the AllExceptions handler in the consumer module.
We also tried to leverage the Disable feature and check the application status on the exception, but we can't even do a basic queries to find out if the application is disabled inside the application. (We tried calling an external module that is not disabled but no luck.)
In the end, every page has to check the site property and throw an exception which is caught in that module and redirects to the maintenance page. This isn't great since every page needs to do a query (triggering warnings for every page about using OnInit) and every module needs its own version of the maintenance exception. What we're missing is any one of the following:
- The ability to check if the site is disabled inside the exception handler
- The ability to handle an exception in a layout
- The ability to share an exception handler across modules
- An OnApplicationInitalize action that mirrors OnApplicationReady but fires before any pages are rendered
If anyone has any more clever ideas, please post them up! The "every page checks OnInit" got us through this time, but we have the same requirement for applications with dozens of pages and I am not looking forward to implementing this hack dozens of times.