Solved

Abandon Session on Browser Close or Browsing Away

Posted on 2011-02-11
5
1,198 Views
Last Modified: 2012-05-11
HI All,

When a user logs into my website is creates the Session variable UserID.

When the user logs out using the logout button, I call Session.Abandon() which in turn calls Session_End() within my Global.asax file. This function uses the UserID variable and performs a transaction against my database.

this works really well proving the user uses the damn logout button! But what I am finding is that users are either browsing away from the site or closing their browser down which isn't then performing that all important transaction against my database.

Does anyone have any magic code which can check for users browsing away or browser closing which in turn maintains the session variable whilst calling Session_End()?

Many thanks,

Rit

0
Comment
Question by:rito1
  • 2
  • 2
5 Comments
 
LVL 5

Assisted Solution

by:karthitron
karthitron earned 100 total points
ID: 34870659
While user, closing the browser, you can open your logout page and thereby you can abandon your session, if session persists and update the database. To accomplish this, use OnBeforeUnload event of your master page in body tag. For eg: here i opened google, you can open your logout functionality page.

<body OnBeforeUnload="window.open('http://www.google.co.in');">
0
 
LVL 11

Accepted Solution

by:
b_levitt earned 400 total points
ID: 34871421
This is basically what you want to do:
http://aspalliance.com/1294_CodeSnip_Handle_Browser_Close_Event_on_the_ServerSide.all

Is there a reason you can't rely on the session timeout?
0
 
LVL 1

Author Comment

by:rito1
ID: 34891519
Thanks both.

B_levitt, I tried to rely on Session Timeout but I want to use the session variable which didn't seem to persist long enough for the global.asax Session_End event when a browser is closed.
0
 
LVL 11

Expert Comment

by:b_levitt
ID: 34896220
I'm not sure what you mean that the session variable didn't seem to persist long enough.

Either way does the link I pasted answer your question?
0
 
LVL 1

Author Closing Comment

by:rito1
ID: 34896260
Thanks Both, - b_levitt, thanks for the link.

Rit
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now