Coldfusion Maintenance Page

http://www.bennadel.com/blog/1118-creating-a-down-for-maintenance-page-using-application-cfc.htm

I found this nifty tutorial  "Creating A "Down For Maintenance" Page Using Application.cfc", and using the cfc method referenced in the article it works great, but I need to be able to access the site from my IP address.

So my question is how would you  check for cgi.remote_addr ?

My thought was to check before the cffunction tag like this:

--------------------------------------------------------------------------------------

<cfif cgi.remote_addr NEQ 72.xxx.xxx.xxx>
<cffunction
      name="OnRequestStart"
      access="public"
      returntype="boolean"
      output="true"
      hint="Fires at the beginning of a page requested before the requested template is processed.">
   
 

      <!--- Define arguments. --->
      <cfargument
            name="TargetPage"
            type="string"
            required="true"
            hint="The template that was requested by the user."
            />

      <!--- Define the local scope. --->
      <cfset var LOCAL = StructNew() />


      <!--- Set header code. --->
      <cfheader
            statuscode="503"
            statustext="Service Temporarily Unavailable"
            />

      <!--- Set retry time. --->
      <cfheader
            name="retry-after"
            value="3600"
            />


      <h1>
            Down For Maintenance
      </h1>

      <p>
            The web site is current down for maintenance and will be back up shortly. Sorry for the inconvenience.
      </p>


      <!---
            By returning false, the rest of the page
            rendering will hault.
      --->
      <cfreturn false />
   
</cffunction>
</cfif>


--------------------------------------------------------------------------------

But that just throws error.   Can someone show me how to code this?

Thanks in advance!
Bang-O-MaticAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

_agx_Commented:
Try putting the logic inside the function. Something like this

<cffunction ....>
    .... arguments here ....

     <!--- the ip is not allowed --> 
     <cfif cgi.remote_addr NEQ "72.xxx.xxx.xxx">
          ... down for maintenance headers/message

         <!--- abort processing --->
         <cfreturn false>
     </cfif>
 
     <!--- if it's a valid ip, continue processing --->
     <cfreturn true>
</cffunction>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gurpreet Singh RandhawaCEOCommented:
what error it throws down, can u elaborate on this
0
Bang-O-MaticAuthor Commented:
_agx_
Works perfect! Thank you!
0
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

Bang-O-MaticAuthor Commented:
Just as a follow up, this worked perfect on localhost, returning the html message.

when I ran it on production server it returns the correct http status code:

HTTP/1.1 503 Service Unavailable =>
Cache-Control => private
Content-Type => text/html
Retry-After => 3600
Vary => Accept-Encoding
Server => Microsoft-IIS/7.5
Set-Cookie => CFTOKEN=0; Expires=Fri, 10-Mar-2045 03:14:30 GMT; Path=/
X-AspNet-Version => 2.0.50727
X-Powered-By => ASP.NET
Date => Wed, 11 Mar 2015 19:23:00 GMT
Connection => close

but does not show the html "down for maint." text, it only shows "The service is unavailable"  Any ideas on this?  Only difference in setup is on localhost im running coldfusion 11 and on production server running railo4
0
_agx_Commented:
Edit:
Hm.. that sounds like it is displaying an IIS error message, rather than the custom text.

I am not near IIS/Railo at the moment.  Any change if you return a different status code temporarily? Try something other than 503.  

Just wondering if IIS is suppressing the custom message and displaying its own error handler instead.
0
Bang-O-MaticAuthor Commented:
thanks _agx_ the problem was that I didnt have a custom error page configured in IIS for status code 503.  Once I did that, it all works! Thanks again.
0
_agx_Commented:
Ah, that makes sense.  Glad you figured it out.
0
Bang-O-MaticAuthor Commented:
I followed your advice and returned a 404 status code (i had a custom error page for 404) and that did display the "down for maint." html message. So thanks again _agx_!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.