I use the app_offline.htm file to bring my site down when I have to roll a new revision. However, even after I launch I’d like to be able to play around and test my site before anyone else has access. Since almost all of my pages are available without logging in, I need to way to lock down my application to everyone but myself and obviously the app_offline.htm file won’t for for this.
I have a BasePage class and I’m thinking the only way to do this would be to put code in that class’s Page_Init method and I could check for my specific IP address and kick everyone whose IP doesn’t match to the app_offline.htm file. However, I’m wondering if this would be the best method since my IP will change.
One possibility would be to put a .htaccess file at the root of your site. You could setup a login with only you having access. Once you are ready to return to full access, just remove the login portion of your .htaccess file (if you have other reasons for the file) or just remove it from the site (if the login is all it does)
Well, that is a bit of a design flaw in app_offline.htm, isn’t it?
We’ve built this feature a few times using a configuration switch. We’d then check for said switch and cookie people who had the “special” sauce [no more complicated than a query string parameter] on their first request. If so, they got passed into the site and eveything worked as normal. If not, we sent them to an app_offline-like page, with appropriate HTTP headers/status codes.
PS: felt like walking down memory lane today. Here is the code in question:
private void handleSiteStatus()
{
bool showpage=false;
//Handle site status.
//check for webservice call
if (Request.Path.IndexOf(".asmx")==-1)
{
switch ((int)Public.Site.Components.Config.ConfigController.Site.Status)
{
//Site is down, send everyone to maintentence page.
case (int)TheSite.Helpers.Config.SiteStatus.Down:
Server.Transfer(Public.Site.Components.Config.ConfigController.Site.MaintenancePage);
break;
//Site is maintentence mode. Pass people with the showpage query parameter or if showpage is stored in the session.
case (int)TheSite.Helpers.Config.SiteStatus.Maintenence:
if (Request.QueryString["showpage"]!=null)
{
System.Web.HttpCookie ck=new HttpCookie("showpage", Request.QueryString["showpage"]);
Response.Cookies.Add(ck);
showpage=true;
}
if (!showpage && Request.Cookies["showpage"]==null)
Server.Transfer(Public.Site.Components.Config.ConfigController.Site.MaintenancePage);
break;
}
}
}