Archive

Archive for January, 2012

Put the website in Maintenance Mode (Under Construction)

January 5, 2012 Leave a comment

Global.asax:
void Application_BeginRequest(object sender, EventArgs e)
{
if (ConfigurationManager.AppSettings["MaintenanceMode"] == "true")
{
if ((ConfigurationManager.AppSettings["ByPassUrl"].Contains(
HttpContext.Current.Request.UserHostAddress.ToString())) || (Request.IsLocal))
{
}
else
{
HttpContext.Current.RewritePath("maintenance.aspx");
}
}
}

Also, if you want to make the application available for certain IPs (to test the application from different machines or restrict the usage to them only), you may include their IPs in the web config and add this to your code:

Web.config:

<add key="MaintenanceMode" value="true" />
<add key="ByPassUrl" value="127.0.0.1" />

//Add list of IP addresses to bypass

Categories: ASP.Net 3.5