Forum  General Visual ...  How do I...?  Get a Session Timeout Event
Previous Previous
 
Next Next
New Post 2/20/2010 10:55 AM
  neobender
17 posts
No Ranking


Get a Session Timeout Event 

Hello,

i've searched in this forum for a solution to get a Session Timeout event. But I only find the 'ThreadExit' Event, but it only works in my debug environment (VS2005) if I shut down the WebDev Server an a SessionId in this event is also not available.

Anyways, I store Userdata into static variables and want to remove them if he exit the application. I set the timeout to 20 minutes (in Debug to one), so after 20 minutes or even if the session is closed, invalid or what ever I want to remove the Userdata from cache. How does it works? Is there any posibillity to register a event when a Session is going to close?

 
New Post 2/21/2010 2:39 PM
  SplitMerge
75 posts
www.hrtms.com
No Ranking


Re: Get a Session Timeout Event 
Modified By SplitMerge  on 2/21/2010 5:44:20 PM)

We have had to deal with a similar issue. I am not sure if we did it correctly, but here is our approach:

1. Create a Global.ASAX file, and write code for the Session_End event.

2. We used a database table to track active sessions. I think that is a safer way than a static variable because if you decide to deploy your application on multiple application pools, each pool will hold a copy of the static variable, which means you can't really tell who is active on the system (each version of the application will only see its copy of the static variable).

3. We also added a 'heartbeat' timer to the main form of the application, and set it to 60 seconds. Each timer event updates the database 'ActiveSession' table with the last time each client was heard from. This catches cases where the user simply closes the browser - their last heatbeat will indicate an inactive session, which we can delete periodically. Our hearbeat timer is also used to display broadcast messages. We have found that its very useful to be able to broadcast to everyone who is active in the application (such as 'System down for maintenace at 4:00pm.. please save your work').

4. We have an explicit logoff in the application, and if the user clicks that, we delete their 'ActiveSession' record.

5. We wrote an admin screen that shows the active users in the application, and we give the administrator the option to just delete the session record manually.

Overall, this approach seems to achieve what we needed, which is a way to tell who is on the system at any time, and optionally communicate with them. We mainly use the ActiveSession to logically lock records.. so if someone is working on a particular record, other users can't update the same record.

In my testing, i have found the global.asax Session_End event is not very dependable. Not sure why.. but I don't think its solid enough to use by itself.

In reading your posting, if you are only caching user-data for performance reasons,.. you may as well put that data into a session variable since your overall memory footprint will be the same. In that case, when the session dies, it will release the userdata.

One last comment: I posted a note about this elsewhere, but I believe that VWG Server is holding onto the Mainform object and never releasing it. In my testing, i have never seen a destructor event fired for the main class, which indicates to me that they are locked in memory forever, even if the session is closed. Maybe someone else has noticed this as well. What this means is that any module-level variables that you may hold in your main form may never get released.

Well, I hope that makes sense. If there are other dependable ways to do this, we would like to hear about them.

Mitch Stephens

HRTMS

 

 
New Post 3/20/2010 3:25 PM
  palli
11189 posts
1st Level Poster




Re: Get a Session Timeout Event 

Hi Mitch,

Thanks for sharing your solution.

I think this is a nice solution you have here, and you get the overview you require. Not that it matters, but the only question that popped into my mind while reading was if you had implemented a forced logout, even for all users at once?

Anyway, I did already reply on your other thread here that my test showed that releasing of the memory occupied by your mainforms does not necessarily occur right away, but later when the garbage collection kicks in.

I also tested the Global.Asax session_end in similar manner, and when you explicitly destroy the session, that event gets fired right away. My test also showed the same for when the session times out, the event gets fired too. This means that if a user opens a session and then closes the browser, there will be a "sessiontimeout" wait interval until the session is destroyed, but then that event does fire.

The conclution I reach from the tests is that both the destructors of MainForms and the Global.asax session_end are reliable, but there might be timing delays involved until they do fire.

P.S. On Visual Studio dev server, the session end does not fire when the user closes the browser. The reason is most likely that the dev server is shut down before the event has the chance to fire. Deployed on IIS, the behaviour is correct.

Thanks again for sharing your ideas,

Palli

 


Páll Björnsson - Visual WebGui support team - Email: support@visualwebgui.com
 
New Post 12/23/2010 5:59 AM
  AlbertoRubini
19 posts
No Ranking


Re: Get a Session Timeout Event 

Hi palli,

I use VWG 6.3.14 and i've trying to use the global.asax to logging when the session expired

I add the EventLog.writeentry and also a writer text file into session_end event, but it not fire.

To test the session timeout, i set the sessionTimeout (asp.net) at "1" (one minute). The application logoff correctly (after 1 minute) but the event not fire.

There's any configuration?

I try it in IIS environment

thanks in advanced for reply

Here there's a project test

Alberto

 
New Post 12/31/2010 7:56 AM
  palli
11189 posts
1st Level Poster




Re: Get a Session Timeout Event 

Hi Alberto,

I tested your project on 6.3.14 both within Visual Studio and deployed to IIS. I did minor changes, as the session timeout needed to be set to 1 minute within web.config, and then within the Global.asax, I have the habit of calling StreamWriter.Flush() and Close() to make sure everything is cleaned up properly.

Both within VS and deployed to IIS, the Global.Asax event fires and writes to both the eventlog and the text file.

So I am not able to reproduce your problem.

What I did (after adjusting session timeout within web.config) was running the app, click the button to log on and then wait for a little more than one minute... and the event fires correctly.

Palli

 


Páll Björnsson - Visual WebGui support team - Email: support@visualwebgui.com
 
Previous Previous
 
Next Next
  Forum  General Visual ...  How do I...?  Get a Session Timeout Event
Azure banner
.NET Web, Cloud and Mobile application delivery platform | Sitemap | Terms of Use | Privacy Statement | Copyright © 2005-2011 Visual WebGui®       Visual WebGui weblog on ASP.NET Visual WebGui Group on LinkedIn Visual WebGui updates on Twitter Visual WebGui Page on Facebook Visual WebGui YouTube Channel Visual WebGui Platform News RSS