• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 310
  • Last Modified:

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!
0
Bang-O-Matic
Asked:
Bang-O-Matic
  • 4
  • 3
1 Solution
 
_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
 
Gurpreet Singh RandhawaWeb DeveloperCommented:
what error it throws down, can u elaborate on this
0
 
Bang-O-MaticAuthor Commented:
_agx_
Works perfect! Thank you!
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now