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?
Thankyou
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.
There’s a much simpler way to do this and it uses a special page called
App_Offline.htm.For more information:
You might also want to read the follow up by Scott about a gotcha with IE6:
When not in use just rename it to something like
App_offline.disabledthen when you need to do maintenance rename it back toApp_Offline.htmagain.A further justification for this approach is that if your “maintenance” includes deploying the site or editing your
web.config, yourUnderMaintainance.aspxpage 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 yourweb.config.App_Offline.htmis great because it means you can really mess up your deployment and no-one will know.