Skip to main content
Inspiring
August 30, 2013
Question

onSessionEnd actually doing anything?!

  • August 30, 2013
  • 1 reply
  • 913 views

i want to do something very simple: when session expires, automatically redirect to a login page.

onSessionEnd looks like the logical choice, but i wasn't able to make it do anything at all!

any example that can show this function can do stuff is welcome, i've tried a bunch of them already, nothing works.

<cfcomponent output="false">

    <cfset this.name="testApp" />

    <cfset this.sessionManagement = true />

    <cfset this.applicationTimeOut = CreateTimeSpan(0,0,0,20) />

    <cfset this.sessionTimeout = createTimeSpan(0,0,0,20) />

    <cfset this.clientManagement = true />

    <cffunction name="onSessionEnd" access="public" returntype="void" output="false">

        <cflocation url="login.cfm">

    </cffunction>

</cfcomponent>

This topic has been closed for replies.

1 reply

Inspiring
August 30, 2013

Think through what you're suggesting.

A session times out after an inactivity people, so intrinsically doesn't (and can't!) happen as part of a request... because a request implies activity. To redirect a request... there needs to be a request being made. But there is no request being made when a session times out.

You cannot interact with the browser in onSessionEnd(), because onSessionEnd() isn't - by definition - connected to browser activity.

What you want to do is to redirect to the login page when the session starts, not when it ends. Intrinsically the request after a session has ended will start a new session... and the redirect to the login page.

Make sense?

--

Adam

ionAuthor
Inspiring
August 30, 2013

Thanks Adam, i've put the call to login page inside onSessionStart. What happens is, i'm using cftooltips ajax style (passing val as url param to a page). Everything works fine, until session ends. When that happens, the tootltip shows (part of) the login page instead of the value passed

Now, Ajax is itself a request, would something like this work, if i create a onRequestStart function, checking for a session var, if not there, can i force onSessionStart to run? something like:

<cffunction name="onRequestStart">

     <cfif session.someVar eq ''>

           <cfscript>StructClear(session);</cfscript>

           <cflocation url="login.cfm">

     </cfif>

</cffunction>

Regards