Click here to Skip to main content
13,301,100 members (81,963 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


32 bookmarked
Posted 4 Jul 2011

Put the website in Maintenance Mode (Under Construction)

, 25 Dec 2011
Rate this:
Please Sign up or sign in to vote.
This Tip/Trick shows how to make the website available only for the local clients
First, you need to add a key/value to your web.config file, so you can turn the maintenance mode ON or OFF.

<add key="MaintenanceMode" value="false"/> <!-- true/false -->

Then put this code block in the Application_BeginRequest of the Global.asax

void Application_BeginRequest(object sender, EventArgs e)
          if (ConfigurationManager.AppSettings["MaintenanceMode"] == "true")
              if (!Request.IsLocal)

Now if you set the "MaintenanceMode" key in the config to true, all the requests from the remote clients will be redirected to the maintenance.aspx page, but the requests from local client will be served normally.

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:

if (!Request.IsLocal && !allowedIPs.Contains(Request.UserHostAddress))


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


About the Author

Bahram Ettehadieh
Web Developer
Iran (Islamic Republic of) Iran (Islamic Republic of)
I hold a BS degree in software engineering and am a Microsoft Certified Solution Developer(MCSD).
I have more than 8 years of experience in .NET developement, mostly web develop using C# and ASP.NET.

You may also be interested in...

Comments and Discussions

Question5 out of 5... Nice trick Pin
rohit kakria15-Jun-12 0:16
memberrohit kakria15-Jun-12 0:16 
QuestionHow to overide login.aspx? Pin
toy4fun14-May-12 21:45
membertoy4fun14-May-12 21:45 
GeneralHttpContext.Current.RewritePath("maintenance.aspx"); gives f... Pin
Mukund Thakker23-Feb-12 1:17
memberMukund Thakker23-Feb-12 1:17 
GeneralIt might be better to redirect to a html page instead of .as... Pin
Tomz_KV3-Jan-12 10:05
memberTomz_KV3-Jan-12 10:05 
GeneralReason for my vote of 5 Thanks for this nice Configuration. Pin
Member 43208443-Jan-12 8:39
memberMember 43208443-Jan-12 8:39 
GeneralReason for my vote of 5 its very simple Pin
manojbdhobale28-Dec-11 20:05
membermanojbdhobale28-Dec-11 20:05 
GeneralReason for my vote of 5 nice tip Pin
Monjurul Habib28-Dec-11 9:17
memberMonjurul Habib28-Dec-11 9:17 
GeneralReason for my vote of 5 Simple to understand. Basic concept ... Pin
Sunil Mane 00718-Dec-11 19:17
memberSunil Mane 00718-Dec-11 19:17 
GeneralReason for my vote of 3 works, just not elegant Pin
Reiss29-Nov-11 5:49
memberReiss29-Nov-11 5:49 
Reason for my vote of 3
works, just not elegant
GeneralReason for my vote of 5 Thanks for sharing. Pin
linuxjr5-Jul-11 6:11
memberlinuxjr5-Jul-11 6:11 
GeneralReason for my vote of 5 Nice tips/Tricks.. Very simple in u... Pin
jawed.ace5-Jul-11 2:55
memberjawed.ace5-Jul-11 2:55 
GeneralThanks for the comment, fixed it Pin
Bahram Ettehadieh5-Jul-11 1:15
memberBahram Ettehadieh5-Jul-11 1:15 
GeneralI think a typo my have crept into the spelling of maintenanc... Pin
George Swan4-Jul-11 20:54
memberGeorge Swan4-Jul-11 20:54 
GeneralReason for my vote of 5 Excellent tip; very simple and pract... Pin
DrABELL4-Jul-11 10:42
memberDrABELL4-Jul-11 10:42 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171207.1 | Last Updated 25 Dec 2011
Article Copyright 2011 by Bahram Ettehadieh
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid