Click here to Skip to main content
15,885,365 members
Articles / Web Development / ASP.NET
Alternative
Tip/Trick

Put the website in Maintenance Mode (Under Construction)

Rate me:
Please Sign up or sign in to vote.
4.67/5 (3 votes)
27 Dec 2011CPOL 13.2K   4   2
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:

C#
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:

XML
<add key="MaintenanceMode" value="true" />
<add key="ByPassUrl" value="127.0.0.1" />
//Add list of IP addresses to bypass

from viewing offline page.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
India India
Project Lead
MCTS - .NET Framework 4.0, Web Applications

Blog : http://thakkermukund.wordpress.com
Twitter@thakkermukund

Don't code today, what you can't debug tomorrow!
Everything makes sense in someone's mind

Comments and Discussions

 
GeneralReason for my vote of 5 good, keep it up. Pin
kelvin z2-Jan-12 23:09
kelvin z2-Jan-12 23:09 
GeneralRe: Thanks Kelvin Pin
Mukund Thakker2-Jan-12 23:14
professionalMukund Thakker2-Jan-12 23:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.