65.9K
CodeProject is changing. Read more.
Home

Put the website in Maintenance Mode (Under Construction)

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.67/5 (3 votes)

Dec 27, 2011

CPOL
viewsIcon

13633

Here is the source code for another solution:Global.asax:void Application_BeginRequest(object sender, EventArgs e){ if (ConfigurationManager.AppSettings["MaintenanceMode"] == "true") { if ((ConfigurationManager.AppSettings["ByPassUrl"].Contains( ...

Here is the source code for another solution:

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

from viewing offline page.