13

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.

jscs
  • 63,694
  • 13
  • 151
  • 195
Erçin Dedeoğlu
  • 4,950
  • 4
  • 49
  • 69

1 Answers1

11

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

Erçin Dedeoğlu
  • 4,950
  • 4
  • 49
  • 69
  • 1
    This would have been my suggestion. You are essentially inspecting the request early in the HTTP Pipeline and then acting on some boolean value. Seems right to me. – Brett Jan 03 '14 at 20:21
  • This seems to be a great workaround for the app_offline.htm issue in MVC. I used your method, but instead, am using web.config -> appSettings to configure the app state (versus the db), e.g. ``. If this key is present and false, I bypass a lot of other configuring and just serve up the static .htm page like your example. Thanks again for getting me there. – secretwep Jul 21 '20 at 22:30