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.