I 'm developing an application in Flash & AS3 and I 'm using ColdFusion 8 for flash remoting. Some screens will be used by only 1 user. I googled a lot of times and i got some pages that contain "OnSessionStart", "OnSessionEnd" and "OnRequest" topics, i tried to use in my cfc but no sense. I want to clear usage status of the screen in my application. If i can catch the "session-end" event, i can clear the usage field in database. So if an user close the browser window not properly, value of the field will be resetted and another user can use the screen safely.
Please help. Thanks.
If you're just worried about how to handle the end of a session and user logins/logouts, there's some good info in this thread that might help you:
Your OnSessionStart, OnSessionEnd, etc. methods need to go into Application.cfc. Inside each method, you define what you want to do when a new session starts, when a session ends, etc. Depending on the application, you may or may not always have a reliable way to determine if a session or an application session has ended...if the user leaves his browser window opens and then walks away, the session will stay open until the timeout value is reached (at which point, onSessionEnd is triggered), so make sure you have a timeout set in Application.cfc and that it's a reasonable value for your application. Inside OnSessionEnd is where you would do any of your cleanup that might need to be done if the user doesn't end his session properly.
Thanks a lot for your reply isis_maat. I checked the link that you wrote too but it can't help me completely i think. Because i m not using a thing such as Application.cfc. Is application.cfc the sharp condition to catch up session-end event? Here is what am I doing: I have a Flash application. I 'm connecting to ColdFusion Flash Remoting servise in back-end. I 'm calling a function from the connected cfc and the results coming into the Flash. Does Application.cfc can be helpful in back-end? As I understood the answer is no but i m not sure, please light me. My Flash application is a module-based application and it is too big. So every module has a cfc such as x_module.cfc, y_module.cfc.. If there must be an Application.cfc, how will i make the coordination as right, it seems hard.
How are you currently doing user and session management, then? Is it being done entirely in Flex? In order to do session management in ColdFusion, you need to have either an Application.cfc (or an Application.cfm...Application.cfc is recommended, however) file in the same folder as the ColdFusion portion of your application. The CF server will automatically invoke Application.cfc before it executes any of your cfc or cfm pages, and automatically execute any of the OnApplicationStart, OnSessionStart, OnRequestStart, OnRequest, OnRequestEnd, OnSessionEnd, OnApplicationEnd or OnError methods you have defined in the Application.cfc file. OnApplicationStart gets triggered when the CF application is first started, OnSessionStart is triggered every time a new session is started, OnRequestStart is triggered at the start of every page request, etc. You don't need to define all of them...in my applications I usually have OnApplicationStart, OnSessionStart, OnRequestStart, OnSessionEnd and OnError defined. You also do not need to worry about when or how to call any of these methods...the CF server will do that for you. All you need to do, essentially, is define what you want to happen when a session starts or ends, when a page request happens, when the application starts, etc. and CF will invoke the appropriate method as you hit each event. A simple Application.cfc file might look something like this:
<!--- This sets the name of your application --->
<!--- Application timeout set to 25 minutes here --->
<cfset THIS.applicationTimeout = createTimeSpan(0,0,25,0)>
<!--- This line enables session management for your entire application --->
<!--- Session timeout set to 25 minutes here --->
<cfset THIS.sessionTimeout = createTimeSpan(0,0,25)
<cffunction name="onApplicationStart" output="false" returntype="void">
<!--- All Application-specific initialization code goes here --->
<cffunction name="onRequestStart" output="false" returntype="void">
<!--- Any code you want to be executed at the beginning of any CF page would go here --->
<!--- For example, you might want to use this method to check and see if a user is logged in --->
<!--- and then either set default values or take some other sort of action if he isn't...redirect him to a login page, for example --->
<cffunction name="onSessionStart" returntype="void">
<!--- any code you want to be executed when a user session starts would go here --->
<cfset SESSION.created = Now()>
Does this help? Also I would really recommend you read the section in the livedocs regarding the Application framework in CF and how to handle session and application data.
Now i got it that CF runs Application.cfc or cfm as automatically. So is that valid for back-end? If that so, i create an Application.cfc in the cfc folder of the my modules and it can handle the events. Currently i have not a session management, it was my big problem. Now it seems solved if Application.cfc will run automatically for back-end too. I will try and write thr result here. Thanks a lot for your helps.
Eventually i did it. I have a lot of cfc files in a folder for my flash application and i m calling them totaly back-end. I created an Application.cfc and it worked as well. When i called a function from any cfc in the folder, first Application.cfc is running and i m starting to manage the session. For example i have a main.cfc and i m calling the "init" method and it is returning session.sessionid to me because the Application.cfc runned before it. So i m taking the sessionid into the flash application and i can use for anything by sending it to the CFCs as parameter when i need.
I wish this can help to anyone. Thanks for help again isis_maat.