Welcome!

ColdFusion Authors: Yakov Fain, Pat Romanski, Liz McMillan, Maureen O'Gara, Greg Ness

Related Topics: ColdFusion

ColdFusion: Article

Ask the Training Staff

Ask the Training Staff

Sometimes I take for granted just how cool ColdFusion really is! The other day one of my programmers asked me how to do what I thought was a fairly easy task.

When I showed him the four lines of CF code he needed, he said, "ColdFusion rocks! It would have taken me 50 lines in PHP to do the same thing!" What could I say, other than "Yep"? Below are a few lines of code that I hope will make your life easier.

Q:How can we prevent a browser from caching the content of our Web pages? For example, our content is constantly changing; if a user browses a page, goes on to other pages, and then uses the back button to return to a previous page, we don't want the user seeing the same content he or she saw the first time - we want the user to see the updated content on that page. Can we do this?
A:Absolutely! Most browsers do cache page content to enhance the performance of site navigation. However, you can put some code into your pages that will instruct the browser not to cache their content. Unfortunately, different browsers require different no-cache parameters, so I use three tags to make sure it works in all browser versions. Place the following code at the top of each page you don't want cached:

<CFHEADER NAME="Expires"
VALUE="#Now()#">
<CFHEADER NAME="Pragma"
VALUE="no-cache">
<CFHEADER NAME="cache-control"
VALUE="no-cache, no-store,
must-revalidate">

Q:Our application needs to send out an e-mail message on behalf of our users; however, our mail server doesn't allow relaying from e-mail addresses outside our domain. We want the message to come from one of our e-mail accounts, but have a reply-to set to the address of the user who sent the message. I don't see any way for CFMAIL to set a "Reply-To" attribute. Can this be done?
A:This is a great question! Yes, it can be done now that CFMAIL can use the CFMAILPARAM tag. You may be aware that you can use the CF-MAILPARAM tag to send multiple file attachments, but you can also use it to send mail header information (like "Reply-To"). Here's all you have to do:

<cfmail to="paul@domain.com"
from="noreply@abcgreet
ings.com"
subject="You have received a Birthday Greeting!">
<cfmailparam name="Reply-To"
value="yourfriend@somedomain.com">
Message body goes here...

</cfmail>
Q:Is there a way to program ColdFusion to restart after so many database connection errors? And, more generally, is there a way of programmatically restarting ColdFusion?
A:Yes and no. Yes in the CF Administrator - you can have CF restart after a certain number of failed requests (page or DB requests). You can get it to restart by checking the "Timeout requests after ___ seconds" box in the Settings section (be sure to set a timeout in seconds - do not leave it set to 0). Also check the "Restart at ___ unresponsive requests" box and plug in a number. Don't set either of these settings too low or CF will be restarting all the time.

There is no CF tag or function to restart the CF service, but you can write a .bat file to issue an NT command to stop or start the service:

net stop "World Wide Web
Publishing Service"
net stop "Cold Fusion
Executive"
net stop "Cold Fusion RDS"
net stop "Cold Fusion
Application Server"
net start "Cold Fusion
Application Server"
net start "Cold Fusion RDS"
net start "Cold Fusion Executive"
net start "World Wide Web
Publishing Service"
and then call that .bat file using CFEXECUTE:

<!--- build a form that has a submit button on it and points to this action page --->
<cfif isDefined("Form.restart")>
<cfexecute
NAME="C:\websrvr\htdocs\restart
svcs.bat"/>
All webservices (IIS & CF)
will be restarted. Please
check back in 30 seconds.
</cfif>
.  .  .

Please send your questions about ColdFusion (CFML, CF Server, or CF Studio) to AskCFDJ@sys-con.com. Visit our archive site at www.netsitedynamics.com/AskCFDJ.

More Stories By Bruce Van Horn

Bruce Van Horn is president of Netsite Dynamics, LLC, a certified ColdFusion developer/instructor, and a member of the CFDJ International Advisory Board.

Comments (1) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
Drew 11/16/07 04:41:05 AM EST

Has anyone actually tried that cf restart method? I've found that when you cfexecute a .bat or .cmd as soon as the CF service stops the script is also terminated and cf doesn't actually get started again.