问题
I'm using the ColdFusion 9 coldfusion.runtime.SessionTracker
to monitor currently logged in users using the following code.
app = application.getApplicationSettings().name;
sessiontracker = createObject("java","coldfusion.runtime.SessionTracker");
sessionCollection = sessionTracker.getSessionCollection(app);
Which returns a struct
of jsessionid
's and the session's variables for all the currently active sessions.
Is it possible to force a session to end given I have the jsessionid
effectively forcing the user to be logged out?
Thanks,
Richard
回答1:
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.
回答2:
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
来源:https://stackoverflow.com/questions/14663205/coldfusion-sessiontracker-and-forcing-the-session-to-end