Administrar una redirección de página de mantenimiento en una aplicación ASP.NET

I would like to use a configuration in the .config file like this:

<appSettings>
  <add key="SiteIsActive" value="false"/>
  <add key="SiteNonActive_RedirectTo" value="UnderMaintainance.aspx"/>
</appSettings>

So that, when the setting is set to the false value, the system automatically redirects EVERY REQUEST to the maintainance page.

I tried to do this in this way: using Global.asax's Application_BeginRequest:

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"]);
}

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!

Is this the right way to achieve my objective? Do I do anything wrong?

Gracias

PS: Internet Explorer does not behave like firefox, it shows me the redirected page correctly.

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:

1) Maintainance

<appSettings>
  <add key="SiteIsActive" value="false"/>
  <add key="SiteNonActive_RedirectTo" value="UnderMaintainance.aspx?S=Maintainance"/>
</appSettings>

2) Under construction

<appSettings>
  <add key="SiteIsActive" value="false"/>
  <add key="SiteNonActive_RedirectTo" value="UnderMaintainance.aspx?S=UnderConstr"/>
</appSettings>

3) Temporary inactivity

<appSettings>
  <add key="SiteIsActive" value="false"/>
  <add key="SiteNonActive_RedirectTo" value="UnderMaintainance.aspx?S=TempInact"/>
</appSettings>

App_Offline does not offer me this.

preguntado el 27 de agosto de 11 a las 17:08

Have you checked out App_Offline.html? Just a tip. -

I think you're over complicating this. You could just keep three different App_Offline pages on the site: App_Offline.maint, App_Offline.under` and App_Offline.temp. Rename the one that applies to App_Offline.htm. It means you can ensure that your .aspx page is never at risk of not running should you muck up a web.config setting for example, or drop a DLL. -

1 Respuestas

There's a much simpler way to do this and it uses a special page called App_Offline.htm.

Para más información:

App_Offline.htm - by Scott Guthrie

You might also want to read the follow up by Scott about a gotcha with IE6:

App_Offline.htm y cómo solucionar la función "Errores compatibles con IE"

When not in use just rename it to something like App_offline.disabled then when you need to do maintenance rename it back to App_Offline.htm de nuevo.

A further justification for this approach is that if your "maintenance" includes deploying the site or editing your web.config, Su UnderMaintainance.aspx page may fail to execute because your site will be in a state of flux whilst it is being uploaded. Or, you may have made a mistake and overwritten these "maintenance" values in your web.config.

App_Offline.htm is great because it means you can really mess up your deployment and no-one will know.

Respondido 27 ago 11, 22:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.