ColdFusion SessionTracker and forcing the session to end

我怕爱的太早我们不能终老 提交于 2019-12-05 15:42:09

So when a user logs in I'm setting a user structure in their session, so to remove their logged in state. Using sessionTracker I can get a specific user's session and just delete the user structure in their current session.

app = application.getApplicationSettings().name;
sessiontracker = createObject("java","coldfusion.runtime.SessionTracker");
sessionCollection = sessionTracker.getSessionCollection(app);

userSession = sessiontracker.getSession(app, sessionID));

structDelete(userSession, "user");

Not sure if this is the best way of doing it but it seems to work for me. Hope it helps people.

Have you tried using the onSessionEnd in the application.cfc? Since we can fire it manually in a logout process or it will fire automatically if the user closes the browser or whatever it works great. This is how we use it.

In the application.cfc we fire the onSessionEnd and it fires the logout function which is also in the application.cfc and does all of the clean stuff and logging.

<cffunction name="OnSessionEnd" access="public" returntype="void"
                 output="false" hint="Fires when the session is terminated.">
        <cfargument name="SessionScope" type="struct" required="true" />
        <cfargument name="ApplicationScope" type="struct"
                                  required="false" default="#StructNew()#" />
        <cfargument name="timedOut" type="boolean" required="false" default="true">
                <cfinvoke thisSessionScope="#SessionScope#"
                      timedOut="#arguments.timedOut#" method="logout">
                </cfinvoke>
            <cfset structClear(arguments.sessionScope) >
         <!--- Return out. --->
        <cfreturn />
    </cffunction>

Hope this helps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!