title: Managing a maintainance page redirect in an ASP.NET application
body: <p>I would like to use a configuration in the .config file like this:</p>
  
  <pre><code>&lt;appSettings&gt;
    &lt;add key="SiteIsActive" value="false"/&gt;
    &lt;add key="SiteNonActive_RedirectTo" value="UnderMaintainance.aspx"/&gt;
  &lt;/appSettings&gt;
  </code></pre>
  
  <p>So that, when the setting is set to the false value, the system automatically redirects EVERY REQUEST to the maintainance page.</p>
  
  <p>I tried to do this in this way: using Global.asax's Application_BeginRequest:</p>
  
  <pre><code>protected void Application_BeginRequest(object sender, EventArgs e) {
    if ((bool)System.Configuration.ConfigurationManager.AppSettings["SiteIsActive"])
      if (this.Request.Path.IndexOf(
         System.Configuration.ConfigurationManager.AppSettings["SiteNonActive_RedirectTo"]) == -1)
        this.Response.Redirect(
        System.Configuration.ConfigurationManager.AppSettings["SiteNonActive_RedirectTo"]);
  }
  </code></pre>
  
  <p>Basically it works, but when redirecting in this way, firefox will show me the page WITHOUT any image or style applied... it's strange, I look at the page source downloaded by the browser and everything is there!</p>
  
  <p>Is this the right way to achieve my objective?
  Do I do anything wrong?</p>
  
  <p>Thankyou</p>
  
  <p>PS: Internet Explorer does not behave like firefox, it shows me the redirected page correctly.</p>
  
  <p>PS2: You guys correctly posted me that a feature called App_Offline is available. Well, I would like not using it for one reason: I would like to use my maintainance page not only to show one status, but more statuses, for example:</p>
  
  <p>1) Maintainance</p>
  
  <pre><code>&lt;appSettings&gt;
    &lt;add key="SiteIsActive" value="false"/&gt;
    &lt;add key="SiteNonActive_RedirectTo" value="UnderMaintainance.aspx?S=Maintainance"/&gt;
  &lt;/appSettings&gt;
  </code></pre>
  
  <p>2) Under construction</p>
  
  <pre><code>&lt;appSettings&gt;
    &lt;add key="SiteIsActive" value="false"/&gt;
    &lt;add key="SiteNonActive_RedirectTo" value="UnderMaintainance.aspx?S=UnderConstr"/&gt;
  &lt;/appSettings&gt;
  </code></pre>
  
  <p>3) Temporary inactivity</p>
  
  <pre><code>&lt;appSettings&gt;
    &lt;add key="SiteIsActive" value="false"/&gt;
    &lt;add key="SiteNonActive_RedirectTo" value="UnderMaintainance.aspx?S=TempInact"/&gt;
  &lt;/appSettings&gt;
  </code></pre>
  
  <p>App_Offline does not offer me this.</p>