Skip navigation
montaana
Currently Being Moderated

Flash remoting and session management

Feb 10, 2010 7:24 AM

Hi

 

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.

 
Replies
  • Currently Being Moderated
    Feb 23, 2010 12:00 PM   in reply to montaana

    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:

    http://forums.adobe.com/message/2092983#2092983

     

    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.

     

    HTH

     

    ~ a

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 25, 2010 8:48 AM   in reply to montaana

    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:

     

     

    <cfcomponent output="false">

     

         <!--- This sets the name of your application --->

        <cfset THIS.name="testApplication">


        <!--- Application timeout set to 25 minutes here --->
        <cfset THIS.applicationTimeout = createTimeSpan(0,0,25,0)>

        <!--- This line enables session management for your entire application --->
        <cfset THIS.sessionManagement=true>
       
       <!--- 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>
       
        <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>
       
        <cffunction name="onSessionStart" returntype="void">

            <!--- any code you want to be executed when a user session starts would go here --->
            <cfset SESSION.created = Now()>
          
           
        </cffunction>
       
    </cfcomponent>

     

    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.

     

    ~ a

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points