asp.net-mvcasp.net-mvc-5app-offline.htm

Take an MVC web site offline and back online


I'm searching for a method to take a website offline with a message. I know about app_offline.htm, but I would like to do it programmatically.

Taking it offline is easy. I can generate app-offline.htm on root, but when I want web site to be back online it is not possible programmatically, because all services are down including images.

My project uses MVC (C#). For now I'm storing the site status in an SQL server database in a bit field.


Solution

  • I find a method to doing it with global.asax but I would like to see other solutions...

        void Application_BeginRequest(object sender, EventArgs e)
        {
            if ((bool) Application["SiteOpenService"] == false)
            {
                if (!Request.IsLocal)
                {
                    HttpContext.Current.RewritePath("/Site_Maintenance.htm");
                }
            }
        }
    

    ref:

    http://www.codeproject.com/Tips/219637/Put-the-website-in-Maintanance-Mode-Under-Construc