Orchard Hungary is an archive

This site is now an archive. We'll keep it so the content is accessible, but we won't update it anymore. However, we frequently publish Orchard-related news on our other site Orchard Dojo, so be sure to check that out instead. And if you're interested in news about our Orchard development company, Lombiq, check out our website.

MVC Brotip: App_Offline

Tags: Orchard, Orchard brotips, brotip, ASP, .NET, MVC, Windows, console

One of the benefits of using ASP.NET MVC is that during maintenance you are able to put your site to an offline state while making changes that could be interrupted or corrupted by users. In case of Orchard these are typically database I/O jobs. To prevent this, all you need to do is place a file named "App_Offline.htm" to the root directory (Orchard.Web) of your site and display any message to the users using HTML. While this file is present, user requests will not reach the Orchard site, instead handled by the server itself. To restore your site to online state, just rename "App_Offline.htm" to anything else.

In addition to this, we speed up this process by using a batch script that is called, for example "SwitchAppState.cmd" (it is placed in the same folder as "App_Offline.htm"):

if exist "App_Offline.htm" (
    ren "App_Offline.htm" "App_Online.htm"
) else (
    if exist "App_Online.htm" (
        ren "App_Online.htm" "App_Offline.htm"
    )
)

It sets site's state to the opposite by renaming "App_Offline.htm" to "App_Online.htm" or vice versa, so changing the state of your site is done by just a doubleclick.

No Comments