Skip to main content
Upen1
Inspiring
September 22, 2010
Question

How to call onSessionEnd Explicitly

  • September 22, 2010
  • 5 replies
  • 1716 views

Hi all,
I have a problem in Application.cfc .Please give some suggestions .

In  my Application.cfc I have created one onSessionEnd function where I am  creating log report of which session exists for how much time. It  works fine only when the session expires automatically but I want make a explicit call  to that function in my log out page.I had tried but it is showing some  error.Is it possible to explicitly call this function.

This topic has been closed for replies.

5 replies

Participant
February 28, 2011

Hi Upen@Roul ,

I got through your lines, but before I could suggest you some thing on this issue I must like to watch the error that you got while calling 'onSessionEnd' method. I guess the issue might be some thing like the method is not defined. If this is the issue, then the most probable solution to this is you must call the methods as Application.method_name. Hope fully this will fix your issue. If you have some other issues, then please mention the error message.

Thanks

Dipak

Upen1
Upen1Author
Inspiring
February 28, 2011

Hi Dipak,

I had written this post a long time ago.So now I can't say you the particular error message .But that time my problem was to expire a session before the expiration of it's time limit .So by using the following piece of code you can do that.

<cfapplication

name="#this.name#"

clientmanagement="Yes"

applicationtimeout="#CreateTimeSpan(0, 0, 20, 0)#"

sessionmanagement="Yes"

sessiontimeout="#CreateTimeSpan(0, 0, 0, 0)#" />

Here we are setting the session time out value as 0 sec.

Upen1
Upen1Author
Inspiring
September 29, 2010

I have tried it and suceed by using this solution--

<cffunction

name="onSessionEnd" output="false">

<cfargument name = "sessionScope" required=true/>

<cfargument name = "applicationScope" required=true/>

<cfset var sessionLength = TimeFormat(Now() - sessionScope.started, "H:mm:ss")>

<cflock name="AppLock" timeout="5" type="Exclusive">

<cfset arguments.applicationScope.sessions = arguments.applicationScope.sessions - 1>

</cflock>

<cflog file="#this.name#" type="Information"

text=

"Session #arguments.sessionScope.sessionid# ended.Length: #sessionLength# Active sessions: #arguments.applicationScope.sessions#">

<cfscript>

StructClear(#arguments.sessionScope#);

</cfscript>

<cfapplication

name="#this.name#"

clientmanagement="Yes"

applicationtimeout="#CreateTimeSpan(0, 0, 20, 0)#"

sessionmanagement="Yes"

sessiontimeout="#CreateTimeSpan(0, 0, 0, 0)#" >

</cffunction>

You can call this method explicitly when ever required.Thanks

Upen1
Upen1Author
Inspiring
September 28, 2010

Hello friends,

     First of all sorry for the late response.

I think I have done that by the following code in the onSessionEnd().

<cfapplication

name="TeamManagementSystem"

clientmanagement="Yes"

applicationtimeout="#CreateTimeSpan(0, 0, 20, 0)#"

sessionmanagement="Yes"

sessiontimeout="#CreateTimeSpan(0, 0, 0, 0)#" >

This code working fine for mu work.Thanks

Owainnorth
Inspiring
September 22, 2010

Put something like this in your onRequestStart method:

<cfif structKeyExists(URL, 'end') >
    <cfset onSessionEnd() />
</cfif>

Then calling *any* page with ?end will end the session.

Inspiring
September 22, 2010

You shouldn't be wanting to call onSessionEnd() explicitly... it's an event handler designed to fire given a specific event.

However it's entirely reasonable for you to have another method which both your explicit logout code and onSessionEnd() calls.  So I recommend factoring-out this code that needs to be called by both onSessionEnd() and your own code into a separate method.

BTW: it would also help when you post something here saying "there's an error" (etc), for you to post the actual error.

--
Adam