Submit Your Site For Free!

Email Address:
* URL:
*
*Indicates Mandatory Field

Terms & Conditions

DevWebProDE
FlashNewz
DevWebPro










When Does A Session Start?

By Raymond Camden
Expert Author
Article Date: 2007-11-29

Darren asks:

I want to use on sessionstart to initiate a session variable and then use that value in a function call to to set the default language for a site but I get an error saying the session var isn't there. Does the session start after the first request? Should I use on application start instead?
No and no. onSessionStart will definitely fire before onRequestStart. Turns out - Darren had another problem. He had written his Application.cfc without the session variables in his onSessionStart, he had hit his site, and then he had modified the onSessionStart. Since his session had already started, the method didn't run again.

There are a few ways to get around this. One simple way is to quickly rename your Application. If you had:

<cfset this.name="findparishiltonsdignitysite">

You can quickly rename it like so:

<cfset this.name="findparishiltonsdignitysite2">

This is kind of hacky, but it will truly force ColdFusion to restart the application next time you hit it.

Another option, and what I typically use, is a URL hack:

<cfif structKeyExists(url,"reset")>
<cfset onSessionStart()>
</cfif>


This will not be single threaded, but during development, you typically don't care about it. I use this same hook to rerun onApplicationStart as well. In fact, during development I'll typically always run the code by appending OR 1 to the end.

Of course, the Nuclear Option is to restart ColdFusion, but even with ColdFusion 8 being super fast, that's overkill.

Comments

About the Author:
Raymond Camden, ray@camdenfamily.com
http://ray.camdenfamily.com

Raymond Camden is Vice President of Technology for roundpeg, Inc. A long time ColdFusion user, Raymond has worked on numerous ColdFusion books and is the creator of many of the most popular ColdFusion community web sites. He is an Adobe Community Expert, user group manager, and the proud father of three little bundles of joy.



DevWebProDE is an iEntry, Inc. ® publication - 1998-2008 All Rights Reserved Privacy Policy and Legal