?
Solved

Abandon Session on Browser Close or Browsing Away

Posted on 2011-02-11
5
Medium Priority
?
1,220 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 5

Assisted Solution

by:karthitron
karthitron earned 400 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 1600 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

743 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